Too Easy Problems
Contest: Hello 2018
Difficulty rating: 1800
Tags: binary search, brute force, data structures, greedy, sortings

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 format:
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 format:
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.

Constraints:
Time limit: 2.0 s
Memory limit: 256.0 MB

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.

Example input:
5 300
3 100
4 150
4 80
2 90
2 300

Example output:
2
3
3 1 4

Example input:
2 100
1 787
2 788

Example output:
0
0

Editorial:
The first observation is that if we solve a problem which doesn't bring us any points, we could as well ignore it and that won't make our result worse. Therefore, there exists an answer in which all problems we solve bring us points. Let's consider only such answers from now on.
Fix k. How to check if we can get exactly k final points? Consider all problems with ai ≥ k. Obviously, only these problems suit us in this case. If there are less than k such problems, we can't get the final score of k. Otherwise, let's choose k problems with the lowest ti from them. If the sum of these ti doesn't exceed T, then the final score of k is possible, and impossible otherwise.
Now we can loop over the value of k and make the check above for each of them. The complexity of such solution is Ω(n2), though.
There are at least two ways to optimize this idea:
1) Use binary search on k. Indeed, if we can get the final score of k, the final score of k - 1 is also possible. In this case, the complexity of the solution will be $$O(n \log n)$$ or $${\mathcal {O}}(n\log ^{2}n)$$, depending on the implementation.
2) Let's slowly decrease k from n to 0 and keep the set of problems with ai ≥ k and the smallest ti, and the sum of ti in the set. Every time there are more than k problems in the set, remove the problem with the highest ti. Find the largest k such that the set contains at least k problems and the sum of their ti doesn't exceed T. This k is the answer. The complexity of this solution is $$O(n \log n)$$.