#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
int n;
ll segAdd[444444],segMax[444444];
void init(int n_){
  n = 1;
  while( n < n_) n *= 2;
}

//[a,b)
void add(int a,int b,int x,int k,int l,int r){
  if(r <= a || b <= l) return;

  if(a <= l && r <= b){
    segAdd[k] += x;
    while(k){
      k = (k-1)/2;
      segMax[k] = max(segMax[2*k+1] + segAdd[2*k+1],segMax[2*k+2] + segAdd[2*k+2]);
    }
  }else{
    add(a,b,x,2*k+1,l,(l+r)/2);
    add(a,b,x,2*k+2,(l+r)/2,r);
  }
}

ll getMax(int a,int b,int k,int l,int r){
  if(r <= a || b <= l) return -11111111111;

  if(a <= l && r <= b) return segMax[k] + segAdd[k];

  ll left  = getMax(a,b,2*k+1,l,(l+r)/2);
  ll right = getMax(a,b,2*k+2,(l+r)/2,r);

  return max(left,right) + segAdd[k];
}

int H,d[111111],h[111111];
int main(void){
  cin >> n >> H;
  for(int i = 0; i < n-1; i++){
    cin >> d[i] >> h[i];
  }

  int res = 0;
  priority_queue<pair<int,int> > que;
  add(0,1,H,0,0,n);
  for(int i = 0; i < n-1; i++){
    que.push(make_pair(h[i],i));
    while(1){
      if(getMax(i,i+1,0,0,n) - d[i] > 0) break;
      if(que.empty()) break;
      int f = que.top().first;
      int s = que.top().second;
      if(getMax(s,i+1,0,0,n) + f <= H){
	int k1 = (H-getMax(s,i+1,0,0,n))/f;
	int k2 = (d[i]-getMax(i,i+1,0,0,n))/f + 1;
	add(s,i+1,f*min(k1,k2),0,0,n);
	res += min(k1,k2);
      }else{
	que.pop();
	que.push(make_pair(H - getMax(s,i+1,0,0,n),s));
      }
    }
    add(i+1,i+2,getMax(i,i+1,0,0,n) - d[i],0,0,n);
  }
  cout << res << endl;
}
### Prompt

Please create a solution in Cpp to the following problem:

problem

You want to get a treasure on the Nth basement floor of a dungeon. First, you are on the 1st basement floor and your health is H (H is a positive integer). Go downstairs. Sometimes physical strength is consumed. The physical strength consumed when descending to the lower floor on each floor is known in advance. On the other hand, there is one recovery fountain on each floor, and you can recover with each use of the fountain. Each has its own health. You will die if your health drops below 0. Also, your health will never be higher than H. You can use the Recovery Fountain as many times as you like, but it will take time to recover. Because of this, you want to use the fountain as few times as possible.

N, H, when given the health consumed when descending downstairs on each floor, and the health to recover when using the recovery fountain once on each floor, underground N without reducing health to 0 or less. Create a program to find the minimum number of times the fountain has been used to reach the floor.

Also, once you go downstairs, you can't go upstairs until you get the treasure.



input

The input consists of N lines. The first line of the input contains two integers N, H (2 ≤ N ≤ 100000 = 105, 1 ≤ H ≤ 10000000 = 107) separated by blanks. N is underground. It means that there is a treasure on the Nth floor, and H is the initial physical strength (physical strength at the stage of arriving at the basement 1st floor of the dungeon) and the maximum physical strength (recovery does not make the physical strength larger than H). ).

In the following N − 1 line, two integers are written separated by a space. For the integers di and hi on the 1 + i line (1 ≤ i ≤ N − 1), di is from the basement i floor to the basement i. + The physical strength consumed when descending to the 1st floor, hi represents the physical strength to recover when using the spring once in the basement i floor (0 ≤ di <H, 1 ≤ hi <H).

There is a way to reach the Nth basement floor in any scoring data. Of the scoring data, 10% of the points satisfy N ≤ 1000 and H ≤ 1000. For 30% of the points, N Satisfy ≤ 1000. For 50% of the points, the minimum number of times the fountain is used does not exceed 106.

Example

Input

10 10
4 2
2 5
6 1
7 3
6 4
9 6
0 8
4 1
9 4


Output

10

### Response

```cpp
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
int n;
ll segAdd[444444],segMax[444444];
void init(int n_){
  n = 1;
  while( n < n_) n *= 2;
}

//[a,b)
void add(int a,int b,int x,int k,int l,int r){
  if(r <= a || b <= l) return;

  if(a <= l && r <= b){
    segAdd[k] += x;
    while(k){
      k = (k-1)/2;
      segMax[k] = max(segMax[2*k+1] + segAdd[2*k+1],segMax[2*k+2] + segAdd[2*k+2]);
    }
  }else{
    add(a,b,x,2*k+1,l,(l+r)/2);
    add(a,b,x,2*k+2,(l+r)/2,r);
  }
}

ll getMax(int a,int b,int k,int l,int r){
  if(r <= a || b <= l) return -11111111111;

  if(a <= l && r <= b) return segMax[k] + segAdd[k];

  ll left  = getMax(a,b,2*k+1,l,(l+r)/2);
  ll right = getMax(a,b,2*k+2,(l+r)/2,r);

  return max(left,right) + segAdd[k];
}

int H,d[111111],h[111111];
int main(void){
  cin >> n >> H;
  for(int i = 0; i < n-1; i++){
    cin >> d[i] >> h[i];
  }

  int res = 0;
  priority_queue<pair<int,int> > que;
  add(0,1,H,0,0,n);
  for(int i = 0; i < n-1; i++){
    que.push(make_pair(h[i],i));
    while(1){
      if(getMax(i,i+1,0,0,n) - d[i] > 0) break;
      if(que.empty()) break;
      int f = que.top().first;
      int s = que.top().second;
      if(getMax(s,i+1,0,0,n) + f <= H){
	int k1 = (H-getMax(s,i+1,0,0,n))/f;
	int k2 = (d[i]-getMax(i,i+1,0,0,n))/f + 1;
	add(s,i+1,f*min(k1,k2),0,0,n);
	res += min(k1,k2);
      }else{
	que.pop();
	que.push(make_pair(H - getMax(s,i+1,0,0,n),s));
      }
    }
    add(i+1,i+2,getMax(i,i+1,0,0,n) - d[i],0,0,n);
  }
  cout << res << endl;
}
```