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

#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>

typedef unsigned long long int uint64;
typedef long long int          int64;
 
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void get_N (int64 *n)
{
  int cnt;
  
  cnt = scanf("%lld", n);

  return;
}

void get_NK (int64 *n, int64 *k)
{
  int cnt;
  
  cnt = scanf("%lld %lld", n, k);

  return;
}

void get_N1234 (int64 *n1, int64 *n2, int64 *n3, int64 *n4)
{
  int cnt;

  if (n2 == NULL) {
    cnt = scanf("%lld", n1);
    return;
  }
  if (n3 == NULL) {
    cnt = scanf("%lld %lld", n1, n2);
    return;
  }
  if (n4 == NULL) {
    cnt = scanf("%lld %lld %lld", n1, n2, n3);
    return;
  }
  cnt = scanf("%lld %lld %lld %lld", n1, n2, n3, n4);
  return;
}

void omit_LF (void)
{
  char c;
  int  cnt;
  
  cnt = scanf("%c", &c);
  return;
}

char *get_S (int64 n)
{
  char *buf;
  int  i;
  int  cnt;

  buf = malloc((size_t)(n * sizeof(char)));
  if (buf == NULL) {
    return NULL;
  }

  cnt = scanf("%s", buf);

  return buf;
}

char *get_SN (int64 max, int64 *size)
{
  char *buf;
  int  i;
  int  n;

  buf = malloc((size_t)(max * sizeof(char)));
  if (buf == NULL) {
    return NULL;
  }

  scanf("%s", buf);

  n = strlen(buf);

  *size = n;
  
  return buf;
}

int64 *get_NSeq (int64 n)
{
  int64 *buf;
  int64 i;

  buf = malloc((size_t)(n * sizeof(int64)));
  for (i=0; i<n; i++) {
    get_N(&buf[i]);
  }

  return buf;
}

typedef struct _tmp_t {
  int64    a;
  int64    b;
  int64    c;  
} tmp_t;


int compare_a(const void *a, const void *b)
{
  tmp_t *x;
  tmp_t *y;

  x = (tmp_t *)a;
  y = (tmp_t *)b;

  if (x->c < y->c) return -1;
  if (x->c > y->c) return 1;

  if (x->a < y->a) return -1;
  if (x->a > y->a) return 1;

  return 0;
}

int compare_b(const void *a, const void *b)
{
  tmp_t *x;
  tmp_t *y;

  x = (tmp_t *)a;
  y = (tmp_t *)b;

  if (x->b > y->b) return 1;
  if (x->b < y->b) return -1;

  return 0;
}

int compare_n(const void *a, const void *b) {
  int64 *x, *y;
  x = (int64 *)a;
  y = (int64 *)b;

  if (*x > *y) return 1;
  if (*x < *y) return -1;
  return 0;
}

void qsort_a (tmp_t *array, int size)
{
  qsort(array, size, sizeof(tmp_t), compare_a);
}

void qsort_b (tmp_t *array, int size)
{
  qsort(array, size, sizeof(tmp_t), compare_b);
}

#define MAX_M (2*(10*10*10*10*10))

tmp_t dt[MAX_M];

int64 get_dt(int64 xi, int64 yi, int64 m) {
  int64 i;
  for (i=0; i<m; i++) {
    if (((dt[i].a - 1) == xi) && ((dt[i].b - 1) == yi)) {
      return dt[i].c;
    }
  }
  return 0;
}

void swap (tmp_t *a, int64 i, int64 j) {
  tmp_t tmp;

  tmp = a[i];
  a[i] = a[j];
  a[j] = tmp;
  return;
}

int main()
{
  int64 N,T;
  int64 i,j;
  int64 cnt;
  int64 *a,*b;
  int64 cost;
  int64 t;
  int64 limit;

  get_N1234(&N, &T, NULL, NULL);

  for(i=0; i<N; i++) {
    get_N1234(&dt[i].a, &dt[i].b, NULL, NULL);
    dt[i].c = dt[i].a + dt[i].b;
  }
  qsort_a(dt, N);

#if 0 // debug
  for (i=0; i<N; i++) {
    printf("dt i=%d a=%lld b=%lld c=%lld\n", i, dt[i].a, dt[i].b, dt[i].c);
  }
#endif

  t = 0;
  cnt = 0;
  cost = 0;
  for (i=0; i<N; i++) {
    t++;
    limit = MIN((i+10), N);
    cost = (dt[i].a * t  + dt[i].b);
    for (j=i+1; j < limit; j++) {
      if (cost > (dt[j].a * t  + dt[j].b)) {
        cost = (dt[j].a * t  + dt[j].b);
        swap (dt, i, j);
        limit = MIN((j+5), N);
      }
    }
    t += cost;
    if (t <= T) {
      cnt++;
    } else {
      break;
    }
  }
  
  printf("%lld", cnt);
  return 0;
}