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 C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <stack>
#include <random>
#include <bitset>
#include <numeric>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
#define rep(x, b, e) for(int x=(b); x<(e); ++x)
#define ford(x, b, e) for(int x=((int)(b))-1; x>=(e); --x)
#define all(c) c.begin(),c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define st first
#define nd second
#define mp(x,y) make_pair(x,y)
typedef short int sint;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it) {
	*this << ((it != d.b) ? ", " : "") << *it;
  }
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int nax = 2e5+5;
const int kax = 40;
pii ab[nax];
int d[kax + 1][nax];
int n, t;

int main() {
	ios_base::sync_with_stdio(false);
	cin >> n >> t;
	rep(i,0,n) {
		cin >> ab[i].st >> ab[i].nd;
		// ab[i].st *= -1;
	}
	sort(ab, ab + n);
	int non_zero_count = 0;
	while (non_zero_count < n && ab[non_zero_count].st != 0) {
		++non_zero_count;
	}
	vi azero;
	rep(i,non_zero_count, n) {
		azero.pb(ab[i].nd);
	}
	ll suma = 0;
	set<pii> besty;
	besty.insert({0,0});
	rep(i,0,sz(azero)) {
		suma = (suma + 1 + azero[i]);
		if (suma <= t) {
			besty.insert({suma, i + 1});
			// printf("wrzucam : %lld, %d\n", suma, i+1);
		} else {
			break;
		}
	}
	// d[n][k] <- minimalny czas, zeby z pierwszych n ziomow, byc w k sklepach
	int k = min(kax, non_zero_count);
	// printf("non zero count : %d\n", non_zero_count);
	rep(i, 0, k+1) rep(j,0,non_zero_count + 1) {
		d[i][j] = t + 1;
	}
	d[0][0] = 0;
	auto help = besty.lower_bound({t+1, 0});
	--help;
	int res = help->nd;
	rep(j, 1, non_zero_count + 1) {
		rep(shops, 0, k + 1) {
			d[shops][j] = d[shops][j - 1];
		}
		rep(shops, 1, k+1) {
			// printf("ab: %d, %d, %d\n", ab[j-1].st, ab[j-1].nd, d[shops - 1][j-1]);
			// printf("%lld or %lld\n", (ll)d[shops][j - 1], 1 + (ll)-ab[j - 1].st * (1 + d[shops - 1][j-1]) + ab[j - 1].nd);
			d[shops][j] = min((ll)d[shops][j - 1], 1 + (ll)ab[j - 1].st * (1 + d[shops - 1][j-1]) + ab[j - 1].nd);
			// printf("d[%d][%d] = %d\n", j, shops, d[shops][j]);
			if (d[shops][j] <= t) {
				int time_left = t - d[shops][j];
				auto he = besty.lower_bound({time_left + 1, -1}); --he;
				res = max(res, shops + he->nd);
			}
		}
	}
	cout << res << endl;
}