Atcoder ABC137D:Summer Vacation(贪心)
D - Summer Vacation
Time Limit: 2 sec / Memory Limit: 1024 MB
Score : 400 points
Problem Statement
There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of Bi after Ai days from the day you do it.
You can take and complete at most one of these jobs in a day.
However, you cannot retake a job that you have already done.
Find the maximum total reward that you can earn no later than M days from today.
You can already start working today.
Constraints
- All values in input are integers.
- 1≤N≤105
- 1≤M≤105
- 1≤Ai≤105
- 1≤Bi≤104
Input
Input is given from Standard Input in the following format:
N M
A1 B1
A2 B2
⋮⋮
AN BN
Output
Print the maximum total reward that you can earn no later than M days from today.
Sample Input 1
3 4
4 3
4 1
2 2
Sample Output 1
5
You can earn the total reward of 5 by taking the jobs as follows:
- Take and complete the first job today. You will earn the reward of 3 after four days from today.
- Take and complete the third job tomorrow. You will earn the reward of 2 after two days from tomorrow, that is, after three days from today.
题意
一共有N个任务和M天,一个人一天只能做一个任务,做完任务之后可以在第Ai天拿到Bi的工资,问M天内最多可以拿到多少工资
思路
贪心,按照领取工资间隔升序排序
设置一个优先队列用来储存当前可以做的任务并且可以在M天内拿到工资的任务的钱数,每次取可以拿到的最大值
代码
1 #include <bits/stdc++.h>
2 #define ll long long
3 #define ull unsigned long long
4 #define ms(a,b) memset(a,b,sizeof(a))
5 const int inf=0x3f3f3f3f;
6 const ll INF=0x3f3f3f3f3f3f3f3f;
7 const int maxn=1e6+10;
8 const int mod=1e9+7;
9 const int maxm=1e3+10;
10 using namespace std;
11 struct wzy
12 {
13 int day,money;
14 }p[maxn];
15 bool cmp(wzy u,wzy v)
16 {
17 return u.day<v.day;
18 }
19 int main(int argc, char const *argv[])
20 {
21 ios::sync_with_stdio(false);
22 cin.tie(0);
23 int n,m;
24 cin>>n>>m;
25 for(int i=0;i<n;i++)
26 cin>>p[i].day>>p[i].money;
27 sort(p,p+n,cmp);
28 priority_queue<int>que;
29 int ans=0;
30 int pos=0;
31 for(int i=1;i<=m;i++)
32 {
33 while(p[pos].day<=i&&pos<n)
34 que.push(p[pos++].money);
35 if(!que.empty())
36 ans+=que.top(),que.pop();
37 }
38 cout<<ans<<endl;
39 return 0;
40 }
Atcoder ABC137D:Summer Vacation(贪心)的更多相关文章
- AtCoder Grand Contest 012 A - AtCoder Group Contest(贪心)
Time limit : 2sec / Memory limit : 256MB Score : 300 points Problem Statement There are 3N participa ...
- 2018.09.16 atcoder Garbage Collector(贪心)
传送门 昨晚打比赛的时候不是很机智啊. 这道题贪心就能过了. 我们可以发现一个明显的结论,每次选的垃圾的距离从大到小排序之后,每个距离对答案的贡献的系数是5,5,7,9,11-也就是最远的是5,其余都 ...
- Codeforces Round #645 (Div. 2) D. The Best Vacation (贪心,二分)
题意:一年有\(n\)个月,每月有\(d_{i}\)天,找出连续的\(x\)天,使得这\(x\)天的日期总和最大,任意一年都能选. 题解:首先要先贪心,得到:连续的\(x\)天的最后一天一定是某个月的 ...
- 2018.07.12 atcoder Go Home(贪心)
传送门 题意简述:大家在数轴上生活,公司在 s. 班车送所有人回家,有 n 个住处,第 i 个位置在 xi,居住了 pi 的人. 保证 xi 互不相同. 大家⼀起投票向前还是向后,如果票数相同就固定向 ...
- AtCoder NIKKEI Programming Contest 2019 C. Different Strokes (贪心)
题目链接:https://nikkei2019-qual.contest.atcoder.jp/tasks/nikkei2019_qual_C 题意:给出 n 种食物,Takahashi 吃下获得 a ...
- 【AtCoder AGC023F】01 on Tree(贪心)
Description 给定一颗 \(n\) 个结点的树,每个点有一个点权 \(v\).点权只可能为 \(0\) 或 \(1\). 现有一个空数列,每次可以向数列尾部添加一个点 \(i\) 的点权 \ ...
- Atcoder Regular Contest 096 D - Sweet Alchemy(贪心+多重背包)
洛谷题面传送门 & Atcoder 题面传送门 由于再过 1h 就是 NOI 笔试了所以题解写得会略有点简略. 考虑差分,记 \(b_i=c_i-c_{fa_i}\),那么根据题意有 \(b_ ...
- AtCoder Beginner Contest 116 D - Various Sushi (贪心+栈)
D - Various Sushi Time Limit: 2 sec / Memory Limit: 1024 MB Score : 400400 points Problem Statement ...
- Atcoder Beginner Contest 118 C-Monsters Battle Royale(贪心)
题目链接 题意就是要让给出的数字去互相取余,看看能得到最小的数事多少. 那么就可以从小到大排序,每一次都贪心地把最小的数作为攻击者,去攻击其他的数字(也就是大的取余小的),然后再一次排序,循环这个过程 ...
随机推荐
- 【♪♪♪】网易云音乐mp3真实地址
参考别人的博客,得到下面的地址,填上ID号即可,后缀的[.mp3]不用输入 http://music.163.com/song/media/outer/url?id= 例如 最终,合并地址为 http ...
- windows下的_vimrc
折腾了一天 在https://keelii.github.io/2016/06/13/awsome-window-vimrc/的基础上进行了一些改动 " ------------------ ...
- oracle中的控制语句
一.条件语句1.流程控制-if else(1)ifif 判断条件 then ...end if;(2)if-elseif 判断条件 then ...else ...end ...
- Shell脚本的条件控制和循环语句
条件判断:if语句 语法格式: if [ expression ] then Statement(s) to be executed if expression is true fi 注意:expre ...
- Java中方法的定义与使用
Java中方法的定义与使用 1.方法的定义: 方法是一段可以被重复调用的代码块. 方法的声明: public static 方法返回值 方法名([参数类型 变量--]){ 方法代码体: return ...
- 锁对象-条件对象-synchronized关键字
1 import java.util.concurrent.locks.Condition; 2 import java.util.concurrent.locks.Lock; 3 import ja ...
- mybatis中返回自动生成的id
当有时我们插入一条数据时,由于id很可能是自动生成的,如果我们想要返回这条刚插入的id怎么办呢. 在mysql数据中我们可以在insert下添加一个selectKey用以指定返回的类型和值: ...
- Charles ios设备抓包
在Mac下做开发,用Fiddler抓包由于离不开Windows比较痛苦,还好有Charles,到官网http://www.charlesproxy.com/可下载到最新版本(若不支持rMBP可拖到Re ...
- [BUUCTF]REVERSE——[ACTF新生赛2020]rome
[ACTF新生赛2020]rome 附件 步骤 无壳,32位程序 32位ida载入,根据提示字符串"You are correct!",找到关键函数func v15 = 'Q'; ...
- Log4j2又爆雷!2.16.0存在DOS风险,升级2.17.0可解决
本以为,经过上周的2.16.0版本升级,Log4j2的漏洞修复工作,大家基本都要告一段落了. 万万没想到,就在周末,Log4j官方又发布了新版本:2.17.0 该版本主要修复安全漏洞:CVE-2021 ...