D. 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 jbetween 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·1051 ≤ 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 ≤ n1 ≤ 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 i  < ans )我们剔除其中花费时间最多的,到能再次满足要求为止。 
③在①和②的基础上,如果剩下的时间不足以完成接下来哪怕一道题了,就不必再作选择,这就是最优解。 

注意贪心的顺序。

代码:

#include <cstdio>
#include <algorithm>
#include <queue>
using namespace std;
struct prob{
    int least,sec,id;
}a[200005];

bool cmp(prob x,prob y){
    return x.sec<y.sec;
}
struct comp{
    bool operator()(const prob &x,const prob &y){
        if(x.least!=y.least)return x.least>y.least;return x.sec<y.sec;
    }
};
priority_queue<prob,vector<prob>,comp> an;
int main(){
    int n,ans=0,top=0,t;
    scanf("%d%d",&n,&t);
    for(int i=0;i<n;i++){
        scanf("%d%d",&a[i].least,&a[i].sec);
        a[i].id=i+1;
    }
    sort(a,a+n,cmp);
    for(int i=0;i<n;i++){
        if(t<a[i].sec)break;//策略③
        if(a[i].least>ans){//策略①
            t-=a[i].sec;
            an.push(a[i]);
            ans++;
            //printf("%d",ans);
        }
        while(!an.empty()&&an.top().least<ans){//策略②
            ans--;
            t+=an.top().sec;
            an.pop();
        }
    }
    printf("%d\n%d\n",ans,ans);
    while(!an.empty())printf("%d ",an.top().id),an.pop();
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值