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 }

最新文章

  1. touch命令
  2. Git学习笔记(四)
  3. 转 漫谈linux文件IO
  4. 【BZOJ】【1052】【HAOI2007】覆盖问题
  5. 【html】【16】高级篇--毛玻璃效果[模糊]
  6. 【HTML5】在head 设置 meta 能更方便开发
  7. less学习笔记(一)
  8. SSH项目过一段时间之后再访问会报一次Could not open Hibernate session for transaction 异常,Caused by: com.mysql.jdbc.CommunicationsException: Communications link failure due to underlyi,再重新方法即可访问成功(通常出现在过了一晚之后再去访问系统)
  9. 项目实战2.2—nginx 反向代理负载均衡、动静分离和缓存的实现
  10. xmoj142
  11. 二、Windows 下 ShellCode 编写初步
  12. Python---Pycharm如何直接上传自己的代码到GitHub
  13. java正则验证
  14. iOS-项目开发1
  15. 蓝精灵:寻找神秘村Smurfs: The Lost Village迅雷下载
  16. [心跳] 使用心跳机制实现CS架构下多客户端的在线状态实时更新以及掉线自动重连
  17. JS—-this指向
  18. CRUD组件的高阶使用
  19. 【名称解释】#001 IIS名词解释
  20. C#中 DateTime , DateTime2 ,DateTimeOffset 之间的小区别 (转载)

热门文章

  1. .NET Core如何配置TLS Cipher(套件)?
  2. 普通用户iptables规则持久化,开机自动恢复
  3. 巩固javaweb的第二十八天
  4. CAS你知道吗
  5. Ganglia 简单介绍与安装
  6. centOS7.4 , gcc4.8.5装cgdb
  7. tomcat源码1
  8. Android 基础UI组件(二)
  9. [源码解析] PyTorch 分布式(14) --使用 Distributed Autograd 和 Distributed Optimizer
  10. gitlab 备份&amp;恢复