Problem:
Score : 800 points

Problem Statement

There are N stores called Store 1, Store 2, \cdots, Store N. Takahashi, who is at his house at time 0, is planning to visit some of these stores.

It takes Takahashi one unit of time to travel from his house to one of the stores, or between any two stores.

If Takahashi reaches Store i at time t, he can do shopping there after standing in a queue for a_i \times t + b_i units of time. (We assume that it takes no time other than waiting.)

All the stores close at time T + 0.5. If Takahashi is standing in a queue for some store then, he cannot do shopping there.

Takahashi does not do shopping more than once in the same store.

Find the maximum number of times he can do shopping before time T + 0.5.

Constraints

All values in input are integers.

1 \leq N \leq 2 \times 10^5

0 \leq a_i \leq 10^9

0 \leq b_i \leq 10^9

0 \leq T \leq 10^9

Input

Input is given from Standard Input in the following format:

N T
a_1 b_1
a_2 b_2
\vdots
a_N b_N

Output

Print the answer.

Sample Input 1

3 7
2 0
3 2
0 3

Sample Output 1

2

Here is one possible way to visit stores:

From time 0 to time 1: in 1 unit of time, he travels from his house to Store 1.

From time 1 to time 3: for 2 units of time, he stands in a queue for Store 1 to do shopping.

From time 3 to time 4: in 1 unit of time, he travels from Store 1 to Store 3.

From time 4 to time 7: for 3 units of time, he stands in a queue for Store 3 to do shopping.

In this way, he can do shopping twice before time 7.5.

Sample Input 2

1 3
0 3

Sample Output 2

0

Sample Input 3

5 21600
2 14
3 22
1 3
1 10
1 9

Sample Output 3

5

Sample Input 4

7 57
0 25
3 10
2 4
5 15
3 22
2 14
1 15

Sample Output 4

3

Solution in Java8 (OpenJDK 1.8.0) (judge verdict: Wrong Answer)

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }

    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int T = scan.nextInt();
        List<Pair> zero_list = new ArrayList<>();
        List<Pair> non_zero_list = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            long a = scan.nextLong();
            long b = scan.nextLong();
            Pair p = new Pair(a, b);
            if (a == 0) {
                zero_list.add(p);
            } else {
                non_zero_list.add(p);
            }
        }

        zero_list.sort(new ZeroPairComparator());
        long[] z = new long[zero_list.size()+1];
        for (int i = 1; i <= zero_list.size(); i++) {
            z[i] = z[i-1] + zero_list.get(i-1).b + 1;
        }
        TreeMap<Long, Integer> zero_tree = new TreeMap<>();
        for (int i = 0; i < z.length; i++) {
            zero_tree.put(z[i], i);
        }

        non_zero_list.sort(new NonZeroPairComparator());
        long[] dp = new long[32];
        Arrays.fill(dp, Long.MAX_VALUE);
        dp[0] = 0;
        int len = non_zero_list.size();
        for (int i = 0; i < len; i++) {
            long[] next_dp = new long[32];
            Arrays.fill(next_dp, Long.MAX_VALUE);
            Pair p = non_zero_list.get(i);
            for (int j = 30; 0 <= j; j--) {
                if (dp[j] == Long.MAX_VALUE)  {
                    next_dp[j] = Math.min(next_dp[j], Long.MAX_VALUE);
                    continue;
                }
                long time = dp[j] + 1 + p.a * (dp[j] + 1) + p.b;
                if (T < time) {
                    next_dp[j] = Math.min(next_dp[j], Long.MAX_VALUE);
                    continue;
                }
                next_dp[j+1] = Math.min(next_dp[j+1], Math.min(dp[j+1],time));

                next_dp[j] = Math.min(next_dp[j], dp[j]);
            }
            dp = next_dp;
        }
        long ans = 0;
        for (int i = 0; i <= 31; i++) {
            if (T < dp[i]) {
                continue;
            }
            long count = i;
            long x = zero_tree.floorKey(T - dp[i]);
            ans = Math.max(ans, count + zero_tree.get(x));
        }
        System.out.println(ans);
    }

    class Pair {
        long a;
        long b;
        Pair(long a, long b) {
            this.a = a;
            this.b = b;
        }
    }

    class ZeroPairComparator implements Comparator<Pair> {
        @Override
        public int compare(Pair o1, Pair o2) {
            return Long.compare(o1.b, o2.b);
        }
    }

    class NonZeroPairComparator implements Comparator<Pair> {
        @Override
        public int compare(Pair o1, Pair o2) {
            double x1 = (double) o1.a / ((double) o1.b + 1);
            double x2 = (double) o2.a / ((double) o2.b + 1);
            return -Double.compare(x1, x2);
        }
    }
}