Codeforces 913D - Too Easy Problems 【优先队列】


D. Too Easy Problems


time limit per test  2seconds

memory limit per test      256megabytes


You are preparing for an exam onscheduling theory. The exam will last for exactly T millisecondsand will consist of n problems. You can either solve problem i in exactly ti milliseconds orignore it and spend no time. You don't need time to rest after solving aproblem, either.

Unfortunately, your teacher considerssome of the problems too easy for you. Thus, he assigned an integer ai to everyproblem i meaning that the problem i can bring you apoint to the final score only in case you have solved no more than ai problemsoverall (including problem i).

Formally, suppose you solve problems p1, p2, ..., pk during theexam. Then, your final score s will be equal to the number of valuesof j between 1 and k such that k ≤ apj.

You have guessed that the real firstproblem of the exam is already in front of you. Therefore, you want to choose aset of problems to solve during the exam maximizing your final score inadvance. Don't forget that the exam is limited in time, and you must haveenough time to solve all chosen problems. If there exist different sets ofproblems 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) — thenumber of problems in the exam and the length of the exam in milliseconds,respectively.

Each of the next n lines containstwo integers ai and ti (1 ≤ ai ≤ n; 1 ≤ ti ≤ 104). The problemsare numbered from 1 to n.

Output

In the first line, output a singleinteger s — your maximum possible finalscore.

In the second line, output a singleinteger k (0 ≤ k ≤ n) — thenumber of problems you should solve.

In the third line, output k distinctintegers p1, p2, ..., pk (1 ≤ pi ≤ n) — theindexes of problems you should solve, in any order.

If there are several optimal sets of problems, you mayoutput 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 solveproblems 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 leavingyourself 30 milliseconds to have a rest). Problems 3 and 1 will bring you apoint each, while problem 4 won't. You'll score two points.

In the second example, the length of theexam is catastrophically not enough to solve even a single problem.

In the third example, you have just enough time to solveboth problems in 42 + 58 = 100 milliseconds and hand your solutions tothe teacher with a smile.



【题意】


现在你有时间T去解决n个题目,每个题目给出 ai 和 ti , ti 表示解决这个题目需要的时间,而 ai 表示只有在做出题目总和不超过(包括这题)ai的情况下,这道题才有效。


问在时间限制内,做哪些题目可以使有效做题数最多。


【思路】


我们先利用vector数组根据ai大小分类,然后对于每一类肯定是时间少的有限考虑,所以考虑用优先队列。


由于题目要求的是最大有效最题数,那么我们只要去由n到0枚举即可。


先把ai为i的题目入队列,然后如果此时队列里的题目数大于i的话,我们需要把时间大的出队列即可(因为队列中的题目ai一定大于等于i,删去哪个都一样)。过程中统计总时间sum确保不超过T即可。


然后再枚举的过程中只要q.size()==i&&sum<=T即满足条件。


#include <cstdio>
#include <cmath>
#include <queue>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
#define mst(a,b) memset((a),(b),sizeof(a))
#define rush() int T;scanf("%d",&T);while(T--)

typedef long long ll;
const int maxn = 200005;
const ll mod = 1e9+7;
const ll INF = 0x3f3f3f3f;
const double eps = 1e-9;

int n,T;
vector<pair<int,int> >vec[maxn];
priority_queue<pair<int,int> >q;

int main()
{
    scanf("%d%d",&n,&T);
    for(int i=1; i<=n; i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        vec[x].push_back(make_pair(y,i));
    }
    ll sum=0;
    for(int i=n; i>=0; i--)
    {
        for(auto u:vec[i])
        {
            q.push(u);
            sum+=u.first;
        }
        while(q.size()>i)
        {
            sum-=q.top().first;
            q.pop();
        }
        if(q.size()==i&&sum<=T)
        {
            printf("%d\n%d\n",i,i);
            while(q.size())
            {
                printf("%d ",q.top().second);
                q.pop();
            }
            puts("");
            return 0;
        }
    }
}





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值