您的位置:首页 > 其它

Codeforces 913D oo Easy Problems

2018-03-08 21:35 435 查看
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.
InputThe 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.
OutputIn 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.

ExamplesInput
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
NoteIn 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.

题意:这场比赛有N道题目,然后会持续T秒,每一道题有一个a 和一个t  解出一道题花费你t秒时间 然后如果你解出的题数不超过a道的话,你的总分就会加1分,然后题目让你求你能获得的最大分数和你解题的数量以及你解出来题的编号。
解题思路: 首先  这个题给我的感觉有点像背包问题,但是这个T有点大,然后你还需要记录路径,背包就被pass了,搜索也不能。然后我就想到了贪心。
一开始的贪心 我是把他们先排个序按照a值最小,解题所需时间最少,然后暴力跑一边。过了样例后我就交了,结果wa在了一个很大的数据上(一开始不知道,后来实在是没想到自己错在哪里,然后就去看了数据)。
然后发现了我思考问题的缺陷。
首先这个题目给了两种权值,那么我们可以把比赛中的题分为4种
(1) a大t小  (2)a大t大   (3)a小t大  (4)a小t小

我忽略了一种情况,就是很多(2)这样的题然后(1)的题更多,然后你其实可以把一个(2)类型的题扔掉,换更多的1,这样的话你所获得的分数才是最大的。然后我想想 暴力有点困难。需要用到优先队列。然后我就更改了一下排序的规则然后优先队列一下敲,就过了。#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;
const int maxn=2e5+10;
int n,m;
long long ans,anssum;
struct Node{
int flag,a1,t;
bool operator < (const Node &u) const
{
return t<u.t;
}
}node[maxn];
priority_queue<Node> qu;
bool cmp(Node a,Node b){
if(a.a1==b.a1) return a.t<b.t;
return a.a1>b.a1;
}
int main(){
int i,j;
scanf("%d%d",&n,&m);
for(i=1;i<=n;i++){
scanf("%d%d",&node[i].a1,&node[i].t);
node[i].flag=i;
}
while(!qu.empty()) qu.pop();
sort(node+1,node+1+n,cmp);
int size=0;
anssum=0;
for(i=1;i<=n;i++){
if(node[i].a1<=size){
printf("%d\n%d\n",size,size);
int t=0;
while(!qu.empty()){
Node k=qu.top();
if(t) printf(" ");
qu.pop();
printf("%d",k.flag);
t=1;
}
printf("\n");
return 0;
}
Node k;
if(anssum+node[i].t<=m){
anssum+=node[i].t;
size++;
qu.push(node[i]);
}
else if(!qu.empty()&&node[i].t<qu.top().t){
anssum-=(qu.top().t-node[i].t);
qu.pop();
qu.push(node[i]);
}
}
printf("%d\n%d\n",size,size);
int t=0;
while(!qu.empty()){
Node k=qu.top();
qu.pop();
if(t) printf(" ");
printf("%d",k.flag);
t=1;
}
printf("\n");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: