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(贪心)的更多相关文章

  1. AtCoder Grand Contest 012 A - AtCoder Group Contest(贪心)

    Time limit : 2sec / Memory limit : 256MB Score : 300 points Problem Statement There are 3N participa ...

  2. 2018.09.16 atcoder Garbage Collector(贪心)

    传送门 昨晚打比赛的时候不是很机智啊. 这道题贪心就能过了. 我们可以发现一个明显的结论,每次选的垃圾的距离从大到小排序之后,每个距离对答案的贡献的系数是5,5,7,9,11-也就是最远的是5,其余都 ...

  3. Codeforces Round #645 (Div. 2) D. The Best Vacation (贪心,二分)

    题意:一年有\(n\)个月,每月有\(d_{i}\)天,找出连续的\(x\)天,使得这\(x\)天的日期总和最大,任意一年都能选. 题解:首先要先贪心,得到:连续的\(x\)天的最后一天一定是某个月的 ...

  4. 2018.07.12 atcoder Go Home(贪心)

    传送门 题意简述:大家在数轴上生活,公司在 s. 班车送所有人回家,有 n 个住处,第 i 个位置在 xi,居住了 pi 的人. 保证 xi 互不相同. 大家⼀起投票向前还是向后,如果票数相同就固定向 ...

  5. AtCoder NIKKEI Programming Contest 2019 C. Different Strokes (贪心)

    题目链接:https://nikkei2019-qual.contest.atcoder.jp/tasks/nikkei2019_qual_C 题意:给出 n 种食物,Takahashi 吃下获得 a ...

  6. 【AtCoder AGC023F】01 on Tree(贪心)

    Description 给定一颗 \(n\) 个结点的树,每个点有一个点权 \(v\).点权只可能为 \(0\) 或 \(1\). 现有一个空数列,每次可以向数列尾部添加一个点 \(i\) 的点权 \ ...

  7. Atcoder Regular Contest 096 D - Sweet Alchemy(贪心+多重背包)

    洛谷题面传送门 & Atcoder 题面传送门 由于再过 1h 就是 NOI 笔试了所以题解写得会略有点简略. 考虑差分,记 \(b_i=c_i-c_{fa_i}\),那么根据题意有 \(b_ ...

  8. AtCoder Beginner Contest 116 D - Various Sushi (贪心+栈)

    D - Various Sushi Time Limit: 2 sec / Memory Limit: 1024 MB Score : 400400 points Problem Statement ...

  9. Atcoder Beginner Contest 118 C-Monsters Battle Royale(贪心)

    题目链接 题意就是要让给出的数字去互相取余,看看能得到最小的数事多少. 那么就可以从小到大排序,每一次都贪心地把最小的数作为攻击者,去攻击其他的数字(也就是大的取余小的),然后再一次排序,循环这个过程 ...

随机推荐

  1. 省时省心DTM,广告转化无难题

    内容来源:华为开发者大会2021 HMS Core 6 App Services技术论坛,主题演讲<华为分析服务,助您打造数智化运营闭环方案>. 演讲嘉宾:华为消费者云服务 分析产品总监 ...

  2. 禁止点击、禁止button触发【c#】

    bts.Attributes["onclick"] = "return false; ";

  3. A Child's History of England.2

    They made boats of basket-work, covered with the skins of animals, but seldom, if ever, ventured far ...

  4. mysql explain using filesort

    创建表,字段tid上无索引(mysql 5.7) CREATE TABLE `test` ( `tid` int(11) DEFAULT NULL, `tname` varchar(12) DEFAU ...

  5. LinkBinTree

    package ch11; import java.util.ArrayList; import java.util.List; import java.util.Stack; public clas ...

  6. 连接 MySQL 数据库出现问题:The server time zone value ‘�й���׼ʱ��‘ is unrecogni....

    出现问题 The server time zone value '�й���׼ʱ��' is unrecogni.... 解决方案 在 URL 后面加上 ?serverTimezone=UTC 如下: ...

  7. 【Linux】【Shell】【text】Vim

    文本编辑器: 文本:纯文本,ASCII text:Unicode: 文本编辑种类: 行编辑器:sed 全屏编辑器:nano, vi vi: Visual Interface vim: Vi IMpro ...

  8. 【Linux】【Services】【Package】yum

    Linux程序包管理(2)       CentOS: yum, dnf       URL: ftp://172.16.0.1/pub/        YUM: yellow dog, Yellow ...

  9. 【Java 8】方法引用

    一.概述 在学习lambda表达式之后,我们通常使用lambda表达式来创建匿名方法.然而,有时候我们仅仅是调用了一个已存在的方法.如下: Arrays.sort(stringsArray,(s1,s ...

  10. @RestController和@Controller的区别与作用

    在springMvc中controller层类上的要使用@Controller来注明该类属于控制层,在controller层常返回的数据形式有以下几种: 页面:静态页面 ModelAndView:返回 ...