CoderForces-913D
You are preparing for an exam on scheduling theory. The exam will last for exactly Tmilliseconds and will consist of n problems. You can either solve problem i in exactly ti milliseconds or ignore it and spend no time. You don't need time to rest after solving a problem, either.
Unfortunately, your teacher considers some of the problems too easy for you. Thus, he assigned an integer ai to every problem i meaning that the problem i can bring you a point to the final score only in case you have solved no more than ai problems overall (including problem i).
Formally, suppose you solve problems p1, p2, ..., pk during the exam. Then, your final score s will be equal to the number of values of j between 1 and k such that k ≤ apj.
You have guessed that the real first problem of the exam is already in front of you. Therefore, you want to choose a set of problems to solve during the exam maximizing your final score in advance. Don't forget that the exam is limited in time, and you must have enough time to solve all chosen problems. If there exist different sets of problems leading to the maximum final score, any of them will do.
Input
The first line contains two integers n and T (1 ≤ n ≤ 2·105; 1 ≤ T ≤ 109) — the number of problems in the exam and the length of the exam in milliseconds, respectively.
Each of the next n lines contains two integers ai and ti (1 ≤ ai ≤ n; 1 ≤ ti ≤ 104). The problems are numbered from 1 to n.
Output
In the first line, output a single integer s — your maximum possible final score.
In the second line, output a single integer k (0 ≤ k ≤ n) — the number of problems you should solve.
In the third line, output k distinct integers p1, p2, ..., pk (1 ≤ pi ≤ n) — the indexes of problems you should solve, in any order.
If there are several optimal sets of problems, you may output any of them.
Example
5 300
3 100
4 150
4 80
2 90
2 300
2
3
3 1 4
2 100
1 787
2 788
0
0
2 100
2 42
2 58
2
2
1 2
Note
In the first example, you should solve problems 3, 1, and 4. In this case you'll spend 80 + 100 + 90 = 270 milliseconds, falling within the length of the exam, 300 milliseconds (and even leaving yourself 30 milliseconds to have a rest). Problems 3 and 1 will bring you a point each, while problem 4 won't. You'll score two points.
In the second example, the length of the exam is catastrophically not enough to solve even a single problem.
In the third example, you have just enough time to solve both problems in 42 + 58 = 100milliseconds and hand your solutions to the teacher with a smile.
题解:
通过优先队列每次把所有分数为i的元素按照时间从大到下出队列知道队列中只剩下i个元素为止,如果当前SumTime<t && pq.size()==i,则当前解为最优解,。
AC代码为:
#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
const int maxn=2e5+; struct node{
int lie;
int ai;
int time;
} stu[maxn]; bool cmp(node a,node b)
{
return a.time < b.time ;
} struct comp{
bool operator()(const node a,const node b)
{
if(a.ai!=b.ai)
return a.ai>b.ai;
return a.time<b.time;
}
}; priority_queue<node,vector<node>,comp> pq; int main()
{
int n,T,cnt=;
cin>>n>>T;
for(int i=;i<n;i++)
{
cin>>stu[i].ai>>stu[i].time;
stu[i].lie=i+;
} sort(stu,stu+n,cmp); for(int i=;i<n;i++)
{
if(stu[i].time > T)
break;
if(stu[i].ai>cnt)
{
T-=stu[i].time;
pq.push(stu[i]);
cnt++;
} while(!pq.empty() && pq.top().ai<cnt)
{
cnt--;
T+=pq.top().time;
pq.pop();
} } cout<<cnt<<endl;
cout<<cnt<<endl; while(!pq.empty())
{
cout<<pq.top().lie<<" ";
pq.pop();
}
cout<<endl; return ;
}
CoderForces-913D的更多相关文章
- Codeforces 913D - Too Easy Problems
913D - Too Easy Problems 思路:二分check k 代码: #include<bits/stdc++.h> using namespace std; #define ...
- coderforces #387 Servers(模拟)
Servers time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...
- coderforces #384 D Chloe and pleasant prizes(DP)
Chloe and pleasant prizes time limit per test 2 seconds memory limit per test 256 megabytes input st ...
- coderforces 731c
题目大意:给出m组数据,每组数据包括两个数Li与Ri,分别表示左右袜子的索引(下标),表示这一天要穿的袜子:而我们要使得每天穿的这两只袜子的颜色相同,所以可以改变袜子的颜色,每次只能改变一只袜子的颜色 ...
- coderforces 721b
题目描述: B. Passwords time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- CoderForces 280B(记忆化搜索)
题目大意:一个纸牌游戏,52张纸牌排成一列,每张纸牌有面值和花色两种属性.每次操作可以用最后一张纸牌将倒数第二张或者倒数第四张替换,但前提是两张牌的花色或者面值相同.问最终能否只剩一张牌. 题目分析: ...
- CoderForces 689A Mike and Cellphone (水题)
题意:给定一个手机键盘数字九宫格,然后让你判断某种操作是不是唯一的,也就是说是不是可以通过平移也能实现. 析:我的想法是那就平移一下,看看能实现,就四种平移,上,下,左,右,上是-3,要注意0变成8, ...
- CoderForces 518C Anya and Smartphone (模拟)
题意:给定一个手机,然后一共有 n 个app,告诉你每个屏幕最多放 k 个,现在要你运行 m 个app,每次都从第一个屏幕开始滑动,每运行一个,它就和前一个交换位置,第一个就不换了,现在问你要滑动多少 ...
- CoderForces 518D Ilya and Escalator (期望DP)
题意:给定 n 个人,在每一时刻一个人进入地铁的概率是 p,站着不动的概率是 1-p,然后问你 t 时间地铁里有多少人. 析:很明显这是一个期望DP,用d[i][j]表示 i 时刻 j 个人进入地铁的 ...
- CoderForces 687C The Values You Can Make (01背包,DP)
题意:给定 n 个硬币和一个值 k,问你在用一些硬币组成面值为 k的这些硬币还能组成多少种其他面值. 析:如果这样说,由这些硬币能组成多少种不同的面值,那么是不是就很熟悉了,这不就是01背包么,这个题 ...
随机推荐
- hash值生成表后缀(分表方案)
//businessId分表目标值,tableSize:表数量,tableSuffix:表后缀 public static String getTableSuffix(String businessI ...
- maven的项目结构
1.标准目录结构: src -main –bin 脚本库 –java java源代码文件 –resources 资源库,会自动复制到classes目录里 ...
- [ISE调试] 在ISE调试过程中,遇到过的warning以及消除办法
1.在generate的过程中,在Map环节遇到了下面这个warning 意思:告诉你是黑盒子,而且他本来在设计里面就是黑盒子. 解决办法:点击图中的,会弹出一个代码文件,是声明这个IP核的文件,代码 ...
- 简单的 smartpointer
水水地 发第一篇blog, 瘦身版的smartpointer. template <typename T> class CountedPtr { private: T* ptr; long ...
- Hadoop2.8.2 运行wordcount
1 例子jar位置 [hadoop@hadoop02 mapreduce]$ pwd /hadoop/hadoop-2.8.2/share/hadoop/mapreduce [hadoop@hadoo ...
- Docker基础与实战,看这一篇就够了
docker 基础 什么是Docker Docker 使用 Google 公司推出的 Go 语言 进行开发实现,基于 Linux 内核的 cgroup,namespace,以及 AUFS 类的 Uni ...
- 学习记录:《C++设计模式——李建忠主讲》3.“组件协作”模式
“组件协作”模式:现代软件专业分工之后的第一个结果是“框架与应用程序的划分”,“组件协作”模式通过晚期绑定,来实现框架与应用程序之间的松耦合,是二者之间协作时常用的模式.典型模式:Template M ...
- vscode加入到鼠标右键
新建.reg的文件,复制下面代码,然后运行 D:\\软件\\VsCode\\Microsoft VS Code\\Code.exe路径改为自己的,必须是两个 \\ 才能生效 Windows Regis ...
- [ubuntu篇] 使用Hexo建立个人博客,自定义域名https加密,搜索引擎google,baidu,360收录
为了更好的阅读体验,欢迎阅读原文.原文链接在此. Part 1: Using Github Pages and Hexo to manage personal blogs. Series Part 1 ...
- php为什么需要异步编程?php异步编程的详解(附示例)
本篇文章给大家带来的内容是关于php为什么需要异步编程?php异步编程的详解(附示例),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助. 我对 php 异步的知识还比较混乱,写这篇是为了 ...