【牛客 - 1080C】tokitsukaze and Soldier(思维,偏序问题)

题干:

链接:https://ac.nowcoder.com/acm/contest/1080/C
来源:牛客网
 

在一个游戏中,tokitsukaze需要在n个士兵中选出一些士兵组成一个团去打副本。
第i个士兵的战力为v[i],团的战力是团内所有士兵的战力之和。
但是这些士兵有特殊的要求:如果选了第i个士兵,这个士兵希望团的人数不超过s[i]。(如果不选第i个士兵,就没有这个限制。)
tokitsukaze想知道,团的战力最大为多少。

输入描述:

第一行包含一个正整数n(1≤n≤10^5)。
接下来n行,每行包括2个正整数v,s(1≤v≤10^9,1≤s≤n)。

输出描述:

输出一个正整数,表示团的最大战力。

示例1

输入

复制

2
1 2
2 2

输出

复制

3

示例2

输入

复制

3
1 3
2 3
100 1

输出

复制

100

解题报告:

按s排个序,然后贪心选就行了,优先队列维护前s[i]大元素。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define FF first
#define SS second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 2e5 + 5;
struct Node {int s;ll v;bool operator<(const Node & b) const {return s > b.s;//按照人数从大到小排序 }
} R[MAX];
struct NN {int id;ll v;NN(int id=0,ll v=0):id(id),v(v){}bool operator<(const NN & b) const {return v > b.v;}
};
priority_queue<NN> pq;//小根堆 
int main()
{int n;cin>>n;for(int i = 1; i<=n; i++) {scanf("%lld%d",&R[i].v,&R[i].s);}ll ans = 0,tmp = 0;sort(R+1,R+n+1);for(int i = 1; i<=n; i++) {tmp += R[i].v; pq.push(NN(i,R[i].v));while(pq.size() > R[i].s) {NN cur = pq.top();pq.pop();tmp -= cur.v;}ans = max(ans,tmp);}printf("%lld\n",ans);return 0 ;
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/439864.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

3.深度学习练习:Planar data classification with one hidden layer

本文节选自吴恩达老师《深度学习专项课程》编程作业&#xff0c;在此表示感谢。 课程链接&#xff1a;https://www.deeplearning.ai/deep-learning-specialization/ You will learn to: Implement a 2-class classification neural network with a single hidden layerUse unit…

一步步编写操作系统 11 实模式下程序分段的原因

cpu中本来是没有实模式这一称呼的&#xff0c;是因为有了保护模式后&#xff0c;为了将老的模式区别开来&#xff0c;所以称老的模式为实模式。这情况就像所有同学坐在同一个教室里&#xff0c;本来没有老同学这一概念&#xff0c;但某天老师领着一个陌生人进入教室并和大家宣布…

【牛客 - 1080D】tokitsukaze and Event(最短路,思维)

题干&#xff1a; 链接&#xff1a;https://ac.nowcoder.com/acm/contest/1080/D 来源&#xff1a;牛客网 这天&#xff0c;tokitsukaze带着她的舰队去才归一儿海探索。这个海域有n个站点&#xff0c;深海舰队控制着这片海域的m条航线&#xff0c;这些航线连接着这n个点&am…

4.深度学习练习:Building your Deep Neural Network: Step by Step(强烈推荐)

本文节选自吴恩达老师《深度学习专项课程》编程作业&#xff0c;在此表示感谢。 课程链接&#xff1a;https://www.deeplearning.ai/deep-learning-specialization/ fter this assignment you will be able to: Use non-linear units like ReLU to improve your modelBuild a d…

一步步编写操作系统21 x86虚拟机bochs 跟踪bios

为了让大家更好的理解bios是怎样被执行的&#xff0c;也就是计算机中第一个软件是怎样开始的&#xff0c;咱们还是先看下图3-17。在图的上面第5行&#xff0c;显示的是下一条待执行的指令&#xff0c;这是程序计数器&#xff08;PC&#xff09;中的值&#xff0c;在x86上的程序…

【CodeForces - 361D】Levko and Array (二分,dp)

题干&#xff1a; Levko has an array that consists of integers: a1, a2, ... , an. But he doesn’t like this array at all. Levko thinks that the beauty of the array a directly depends on value c(a), which can be calculated by the formula: The less value…

5.深度学习练习:Deep Neural Network for Image Classification: Application

本文节选自吴恩达老师《深度学习专项课程》编程作业&#xff0c;在此表示感谢。 课程链接&#xff1a;https://www.deeplearning.ai/deep-learning-specialization/ After this assignment you will be able to: Build and apply a deep neural network to supervised learning…

排序集锦(各种排序算法的特点及性能分析)

关于排序&#xff0c;似乎很简单的很常见的概念&#xff0c;却蕴含着很多技术&#xff0c;下面是从不同的角度&#xff0c;对排序的总结&#xff1a; 直插希 冒泡快 选择堆 1 按照排序特性分类 首先按照排序本身的操作特性可以分为下面几种&#xff1a; 插入排序 直接插入排…

【CodeForces - 689D】Friends and Subsequences(RMQ,二分 或单调队列)

题干&#xff1a; Mike and !Mike are old childhood rivals, they are opposite in everything they do, except programming. Today they have a problem they cannot solve on their own, but together (with you) — who knows? Every one of them has an integer seque…

6.深度学习练习:Initialization

本文节选自吴恩达老师《深度学习专项课程》编程作业&#xff0c;在此表示感谢。 课程链接&#xff1a;https://www.deeplearning.ai/deep-learning-specialization/ 目录 1 - Neural Network model 2 - Zero initialization 3 - Random initialization&#xff08;掌握&…

Java Object类的各个方法

Java中所有的类都继承自java.lang.Object类&#xff0c;Object类中一共有11个方法&#xff1a; public final native Class<?> getClass();public native int hashCode();public boolean equals(Object obj) {return (this obj); }protected native Object clone() th…

【CodeForces - 602D】Lipshitz Sequence(思维,单调栈,斜率单调性)

题干&#xff1a; A function is called Lipschitz continuous if there is a real constant Ksuch that the inequality |f(x) - f(y)| ≤ K|x - y| holds for all . Well deal with a more... discrete version of this term. For an array , we define its Lipschi…

7.深度学习练习:Regularization

本文节选自吴恩达老师《深度学习专项课程》编程作业&#xff0c;在此表示感谢。 课程链接&#xff1a;https://www.deeplearning.ai/deep-learning-specialization/ 目录 1-Package 2 - Non-regularized model 3 - L2 Regularization&#xff08;掌握&#xff09; 4-Dropou…

深入详解JVM内存模型与JVM参数详细配置

本系列会持续更新。 JVM基本是BAT面试必考的内容&#xff0c;今天我们先从JVM内存模型开启详解整个JVM系列&#xff0c;希望看完整个系列后&#xff0c;可以轻松通过BAT关于JVM的考核。 BAT必考JVM系列专题 1.JVM内存模型 2.JVM垃圾回收算法 3.JVM垃圾回收器 4.JVM参数详解 5…

【2019牛客暑期多校训练营(第三场)- A】Graph Games(思维,对边分块)

题干&#xff1a; 链接&#xff1a;https://ac.nowcoder.com/acm/contest/883/A 来源&#xff1a;牛客网 You are given an undirected graph with N\ N N vertices and M\ M M edges. The edges are numbered from 1\ 1 1 to M\ M M . Denote the set S(x)\ S(x) S…

8.深度学习练习:Gradient Checking

本文节选自吴恩达老师《深度学习专项课程》编程作业&#xff0c;在此表示感谢。 课程链接&#xff1a;https://www.deeplearning.ai/deep-learning-specialization/ 目录 1) How does gradient checking work? 2) 1-dimensional gradient checking 3) N-dimensional gradie…

苹果手机看电流判断故障

正常的开机电流 1、按开机键后电流在40mA摆动一下&#xff08;CPU供电正常&#xff09;&#xff1b; 2、到80mA左右摆动一下&#xff08;暂存开始工作&#xff0c;也就是CPU上盖&#xff0c;然后开始进行总线的初始化&#xff09;&#xff1b; 3、指针到120mA左右摆动&#xff…

【CodeForces - 675C】Money Transfers(思维,前缀和)

题干&#xff1a; There are n banks in the city where Vasya lives, they are located in a circle, such that any two banks are neighbouring if their indices differ by no more than 1. Also, bank 1 and bank n are neighbours if n > 1. No bank is a neighbou…

9.深度学习练习:Optimization Methods

本文节选自吴恩达老师《深度学习专项课程》编程作业&#xff0c;在此表示感谢。 课程链接&#xff1a;https://www.deeplearning.ai/deep-learning-specialization/ 目录 1 - Gradient Descent 2 - Mini-Batch Gradient descent 3 - Momentum 4 - Adam 5 - Model with dif…

一步步编写操作系统 22 硬盘操作方法

硬盘中的指令很多&#xff0c;各指令的用法也不同。有的指令直接往command寄存器中写就行了&#xff0c;有的还要在feature寄存器中写入参数&#xff0c;最权威的方法还是要去参考ATA手册。由于本书中用到的都是简单的指令&#xff0c;所以对此抽象出一些公共的步骤仅供参考之用…