codeforces 913D Too Easy Problems

网友投稿 392 2022-09-02

codeforces 913D Too Easy Problems

​​‎ D. Too Easy Problems time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are preparing for an exam on scheduling theory. The exam will last for exactly T milliseconds 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. Examples Input 5 300 3 100 4 150 4 80 2 90 2 300 Output 2 3 3 1 4 Input 2 100 1 787 2 788 Output 0 0

Input 2 100 2 42 2 58 Output 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 = 100 milliseconds and hand your solutions to the teacher with a smile. 题意:给定每个 任务的a[]和t[]分别表示 这场考试 整体做了多少题 如果<=a[i]那么他就可以给我 最后加分+1 如果 >a[i] 就不加分了 那么 我就每次去贰分一下 我做了多少题 然后 每次去判断的时候 如果我a[i]< mid那么就不添加进去 否则添加到队列里 然后都选出来之后 贪心的选一下看 如果这么少的时间我能否凑够我要的mid个 %%%%icefox 太强啦 qwq我哪会啊 要不是他提醒 我差一点就掉分了 然后最后输出方案的时候因为我已经知道答案了 再和贰分验证的时候一样我去输出即可

#include#include#define N 220000using namespace std;int n,T,a[N],t[N],q[N];struct node{ int id,t;}qq[N];inline bool cmp(node a,node b){return a.t=mid) q[++num]=t[i]; sort(q+1,q+num+1);int x=0;if(numT) break; ++x;time+=q[i];if (x>=mid) return 1; }return x>=mid;}int main(){ freopen("cf.in","r",stdin); scanf("%d%d",&n,&T); for (int i=1;i<=n;++i) scanf("%d%d",&a[i],&t[i]); int l=0,r=n; while(l<=r){ int mid=l+r>>1; if (check(mid)) l=mid+1;else r=mid-1; }printf("%d\n",r);printf("%d\n",r);int num=0; for (int i=1;i<=n;++i) if (a[i]>=r) qq[++num].t=t[i],qq[num].id=i; sort(qq+1,qq+num+1,cmp);for (int i=1;i<=r;++i) printf("%d,qq[i].id); return 0;}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:bzoj1669 [Usaco2006 Oct]Hungry Cows饥饿的奶牛
下一篇:bzoj1103&luogu3459 [POI2007]大都市meg
相关文章

 发表评论

暂时没有评论,来抢沙发吧~