Language: C++

//Bokan ga bokka--nn!!
//Daily Lunch Special Tanoshii !!
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define s(x) scanf("%d",&x)
#define maxs 1<<18
class segtree
{
	ll seg[maxs]={};
	ll lazy[maxs]={};
	
	void lazy_evaluate(int x)
	{
		if(x*2+2>=maxs) continue;
		lazy[x*2+1]+=lazy[x];
		lazy[x*2+2]+=lazy[x];
		seg[x*2+1]+=lazy[x];
		seg[x*2+2]+=lazy[x];
		lazy[x]=0;
	}
	ll update(int beg,int en,int idx,int lb,int ub,int val)
	{
		if(ub<beg || en<lb)
		{
			return seg[idx];
		}
		if(beg<=lb && ub<=en)
		{
			lazy[idx]+=val;
			seg[idx]+=val;
			lazy_evaluate(idx);
			return seg[idx];
		}
		if(lazy[idx])
		{
			lazy_evaluate(idx);
		}
		return seg[idx]=max(update(beg,en,idx*2+1,lb,(lb+ub)/2,val),update(beg,en,idx*2+2,(lb+ub)/2+1,ub,val));
	}
	ll query(int beg,int en,int idx,int lb,int ub)
	{
		if(ub<beg || en<lb)
		{
			return -1LLe12;
		}
		if(beg<=lb && ub<=en)
		{
			return seg[idx];
		}
		if(lazy[idx])
		{
			lazy_evaluate(idx);
		}
		return max(query(beg,en,idx*2+1,lb,(lb+ub)/2),query(beg,en,idx*2+2,(lb+ub)/2+1,ub));
	}
}seg_tree;
int main()
{
	int n;ll x;
	scanf("%d %lld",&n,&x);
	seg_tree.update(0,maxs-1,0,0,maxs-1,x);
	priority_queue<pair<ll,ll> >que;
	int ret=0;
	for(int i=0;i<n-1;i++)
	{
		ll x,y;
		scanf("%lld %lld",&x,&y);
		que.push(mp(y,i));
		
		for(;;)
		{
			if(que.empty()) break;
			if(seg_tree.query(i+1,i+1,0,0,maxs-1)>x) break;
			pair<ll,ll>p=que.top(); que.pop();
			int v1=(x-seg_tree.query(p.second,i,0,0,maxs-1)/p.first;
			int v2=(1-seg_tree.query(i+1,i+1,0,0,maxs-1)+x+p.first-1)/p.first;
			if(v1>=v2)
			{
				ret+=v1;
				seg_tree.update(p.second,maxs-1,0,0,maxs-1,v1*p.first);
			}
			else
			{
				ret+=v2;
				que.pop();
				seg_tree.update(p.second,maxs-1,0,0,maxs-1,v2*p.first);
			}
		}
		seg_tree.update(i+1,maxs-1,0,0,maxs-1,-x);
	}
	printf("%d\n",ret);
}

Compiler output:
a.cc: In member function 'void segtree::lazy_evaluate(int)':
a.cc:35:33: error: continue statement not within a loop
   35 |                 if(x*2+2>=maxs) continue;
      |                                 ^~~~~~~~
a.cc: In member function 'll segtree::query(int, int, int, int, int)':
a.cc:65:33: error: unable to find numeric literal operator 'operator""LLe12'
   65 |                         return -1LLe12;
      |                                 ^~~~~~
a.cc: In function 'int main()':
a.cc:82:24: error: 'll segtree::update(int, int, int, int, int, int)' is private within this context
   82 |         seg_tree.update(0,maxs-1,0,0,maxs-1,x);
      |         ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
a.cc:42:12: note: declared private here
   42 |         ll update(int beg,int en,int idx,int lb,int ub,int val)
      |            ^~~~~~
a.cc:94:42: error: 'll segtree::query(int, int, int, int, int)' is private within this context
   94 |                         if(seg_tree.query(i+1,i+1,0,0,maxs-1)>x) break;
      |                            ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
a.cc:61:12: note: declared private here
   61 |         ll query(int beg,int en,int idx,int lb,int ub)
      |            ^~~~~
a.cc:96:49: error: 'll segtree::query(int, int, int, int, int)' is private within this context
   96 |                         int v1=(x-seg_tree.query(p.second,i,0,0,maxs-1)/p.first;
      |                                   ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
a.cc:61:12: note: declared private here
   61 |         ll query(int beg,int en,int idx,int lb,int ub)
      |            ^~~~~
a.cc:96:80: error: expected ')' before ';' token
   96 |                         int v1=(x-seg_tree.query(p.second,i,0,0,maxs-1)/p.first;
      |                                ~                                               ^
      |                                                                                )
a.cc:97:49: error: 'll segtree::query(int, int, int, int, int)' is private within this context
   97 |                         int v2=(1-seg_tree.query(i+1,i+1,0,0,maxs-1)+x+p.first-1)/p.first;
      |                                   ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
a.cc:61:12: note: declared private here
   61 |         ll query(int beg,int en,int idx,int lb,int ub)
      |            ^~~~~
a.cc:101:48: error: 'll segtree::update(int, int, int, int, int, int)' is private within this context
  101 |                                 seg_tree.update(p.second,maxs-1,0,0,maxs-1,v1*p.first);
      |                                 ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:42:12: note: declared private here
   42 |         ll update(int beg,int en,int idx,int lb,int ub,int val)
      |            ^~~~~~
a.cc:107:48: error: 'll segtree::update(int, int, int, int, int, int)' is private within this context
  107 |                                 seg_tree.update(p.second,maxs-1,0,0,maxs-1,v2*p.first);
      |                                 ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:42:12: note: declared private here
   42 |         ll update(int beg,int en,int idx,int lb,int ub,int val)
      |            ^~~~~~
a.cc:110:32: error: 'll segtree::update(int, int, int, int, int, int)' is private within this context
  110 |                 seg_tree.update(i+1,maxs-1,0,0,maxs-1,-x);
      |                 ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:42:12: note: declared private here
   42 |         ll update(int beg,int en,int idx,int lb,int ub,int val)
      |            ^~~~~~