Problem:
投票 (Voting)
問題文
JOI 高校において，ある議題に関して「賛成」か「反対」かを問う採決が行われ，
N
人の生徒が順番に投票を行った．生徒は自分の投票前に，それまでに投票した他の生徒がどちらに投票したかを知ることができた．
i
番目 (
1 ≦ i ≦ N
) に投票した生徒は，次の条件を満たしたとき「賛成」に投票し，満たさなかったとき「反対」に投票した．
直前に投票した
X
i
人の生徒，すなわち
i - 1, i - 2, ..., i - X
i
番目に投票した生徒のうち，
Y
i
人以上が「賛成」に投票した．
ただし，
Y
i
= 0
のときは他の生徒の投票に関わらず「賛成」に投票し，
Y
i
= X
i
+ 1
のときは他の生徒の投票に関わらず「反対」に投票したとする．
各生徒の投票についての情報が与えられたとき，「賛成」に投票した生徒の人数を求めるプログラムを作成せよ．
制約
1 ≦ N ≦ 500 000
．
0 ≦ X
i
≦ i - 1
(
1 ≦ i ≦ N
)．
0 ≦ Y
i
≦ X
i
+ 1
(
1 ≦ i ≦ N
)．
入力される値はすべて整数である．
入力
入力は以下の形式で標準入力から与えられる．
N
X
1
Y
1
X
2
Y
2
:
X
N
Y
N
出力
標準出力に，「賛成」に投票した生徒の人数を
1
行で出力せよ．
入出力例
入力例 1
4
0 1
1 0
1 1
3 3
出力例 1
2
投票は，以下のように
4
人の生徒によって順番に行われた．
1
番目に投票した生徒は，
Y
1
= X
1
+ 1
であるため，「反対」に投票した．
2
番目に投票した生徒は，
Y
2
= 0
であるため，「賛成」に投票した．
直前に投票した
X
3
(= 1)
人の生徒のうち「賛成」に投票したのは
1
人で，これは
Y
3
(= 1)
人以上である．そのため，
3
番目に投票した生徒は「賛成」に投票した．
直前に投票した
X
4
(= 3)
人の生徒のうち「賛成」に投票したのは
2
人で，これは
Y
4
(= 3)
人以上ではない．そのため，
4
番目に投票した生徒は「反対」に投票した．
「賛成」に投票した生徒は
2
人である．したがって，
2
を出力する．
入力例 2
5
0 0
1 1
2 3
3 1
4 3
出力例 2
4
入力例 3
10
0 0
1 2
1 1
1 0
3 1
2 3
1 1
5 3
8 4
7 2
出力例 3
4
情報オリンピック日本委員会
作 『日本情報オリンピック第2回女性部門 本選 競技課題』

Submitted solutions:

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include<utility>
#include<set>
#include<deque>
#include <unordered_map>
#include<string>
#include<map>
#include<cmath>

using namespace std;



int main() {
	int N;
	cin >> N;
	vector<int>y(N + 1, 0), n(N + 1, 0);

	for (int i = 1; i < N + 1; i++) {
		int X, Y;
		cin >> X >> Y;
		if (Y == 0) {
			y[i] = y[i-1]+1;
			n[i] = n[i - 1];
			continue;
		}
		if (Y == X + 1) {
			y[i] = y[i - 1];
			n[i] = n[i-1]+1;
			continue;
		}
		int p = y[i - 1] - y[i - 1 - X];
		if (p >= Y) {
			n[i] = n[i - 1];
			y[i] = y[i - 1] + 1;
		}
		else {
			n[i] = n[i - 1]+1;
			y[i] = y[i - 1];
		}

	}

	cout << y[N]<<endl;
	
}
accuracy: 1
time_ms: 160
memory_kb: 7056
final_rank: 11

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

int main(){
    int n;
    cin >> n;
    vector<int> x(n+1),y(n+1);
    for(int i=1;i<n+1;i++){
        cin >> x[i] >> y[i];
    }
    vector<int> a(n+1,0);
    for(int i=1;i<n+1;i++){
        if(a[i-1]-a[i-x[i]-1]>=y[i]){
            a[i]=a[i-1]+1;
        }
        else{
            a[i]=a[i-1];
        }
    }
    cout << a[n] << endl;
    return 0;
}
accuracy: 1
time_ms: 160
memory_kb: 8916
final_rank: 13

code_snippet: #define NOMINMAX
#define TEST_MODE true

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"

using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep2(i,a,n) for(int i=a;i<(int)(n);++i)
#define rrep(i,n) for(int i=(n)-1;i>=0;--i)
#define reu(i,n) for(int i=1;i<=(int)(n);++i)

#define chmax(a,b) (a=(a)<(b)?(b):(a))
#define chmin(a,b) (a=(a)>(b)?(b):(a))

#define ll long long
#define all(a) begin(a),end(a)
#define int long long

#ifdef LOCAL_ENV
#define dump(x) cerr<<#x<<" : "<<(x)<< "   \t"
#define dumpl(x) dump(x)<<endl
#define cerr_endl cerr<<endl
ofstream ofstream1("out.txt");
#define cout ofstream1

#else
#define dump(x) 
#define dumpl(x)
#define cerr_endl 
#endif

#define abp(o,a,b) cout<<(((o)?a:b))<<endl
#define YEP(x) abp(x,"YES","NO")
#define Yep(x) abp(x,"Yes","No")

const int inf = (int)1 << 60;
ll mod_n = (int)1e9 + 7;

const int MAX = (int)2e6 + 5;
const int MAX2 = 2005;

template<typename T>void ce_vector(vector<T> a) {
#ifdef LOCAL_ENV
	rep(i, a.size() - 1) cerr << a[i] << " "; cerr << a[a.size() - 1] << endl;
#endif 
}

template<typename T>void ce_vector(vector<pair<T, T> > a) {
#ifdef LOCAL_ENV
	rep(i, a.size()) cerr << a[i].first << "," << a[i].second << " "; cerr << endl;
#endif 
}

template<typename T>void o_vector(vector<T> a) {
	if (a.size() == 0) { cout << endl; return; }
	rep(i, a.size() - 1) cout << a[i] << " "; cout << a[a.size() - 1] << endl;
}

template<typename T>void o_vector(vector<pair<T, T> > a) { rep(i, a.size()) cout << a[i].first << "," << a[i].second << " "; cout << endl; }

ll pow_n(ll x, ll n) { ll r = 1; while (n > 0) { if (n & 1)r = (r * x) % mod_n; x = (x * x) % mod_n; n >>= 1; }return r; }


template<typename T>
vector<T> in_vec(int n) {
	vector<T> a(n);
	a.resize(n);
	rep(i, n) cin >> a[i];
	return a;
}

int div_ceil(int a, int b) { int r = a / b; if (a % b != 0)r++; return r; }

ll modular(ll x) {
	return ((x % mod_n + mod_n) % mod_n);
}

// end of template

struct Person {
	int pos, id;

	bool operator<(const Person& p) const {
		return pos < p.pos;
	}
};


struct Solver {
	void solve() {
		int n; cin >> n;
		int cnt = 0;
		vector<int> v(n + 5);
		rep(i, n) {
			int x, y; cin >> x >> y;
			int recent = cnt - v[i - x];
			if (recent >= y) {
				cnt++;
				dumpl(i);
			}
			v[i + 1] = cnt;
		}
		cout << cnt << endl;
	}


};















signed main() {
	ios::sync_with_stdio(false);
	//cin.tie(nullptr);

	cout << fixed << setprecision(2);

	Solver().solve();

#ifdef LOCAL_ENV
	cout << endl;
	cerr << endl << "\x1b[7m ↓ \x1b[0m" << endl;
	system("type out.txt");
#endif
	return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 7044
final_rank: 8

code_snippet: #include <iostream>
#include <vector>

using namespace std;

int main()
{
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	unsigned int N, i, X, Y;
	cin >> N;
	vector<unsigned int> S(N + 1);

	S[0] = 0;
	for (i = 0; i != N; ++i)
	{
		cin >> X >> Y;
		if (S[i] - S[i - X] >= Y) S[i + 1] = S[i] + 1;
		else S[i + 1] = S[i];
	}

	cout << S[N] << '\n';
	return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 5180
final_rank: 1

code_snippet: #line 1 "/opt/library/template.hpp"
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using i64 = long long;
using u32 = unsigned int;
using u64 = unsigned long long;
using i128 = __int128;
using u128 = unsigned __int128;
using f128 = __float128;

template <class T>
constexpr T infty = 0;
template <>
constexpr int infty<int> = 1'000'001'000;
template <>
constexpr ll infty<ll> = ll(infty<int>) * infty<int> * 2;
template <>
constexpr u32 infty<u32> = infty<int>;
template <>
constexpr u64 infty<u64> = infty<ll>;
template <>
constexpr i128 infty<i128> = i128(infty<ll>) * infty<ll>;
template <>
constexpr double infty<double> = infty<ll>;
template <>
constexpr long double infty<long double> = infty<ll>;
#define inf infty<ll>

using pi = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vector<ll>>;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vc<T>>;
template <class T>
using vvvc = vector<vvc<T>>;
template <class T>
using vvvvc = vector<vvvc<T>>;
template <class T>
using vvvvvc = vector<vvvvc<T>>;
template <class T>
using pq = priority_queue<T>;
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;

#define vv(type, name, h, ...) \
  vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...)   \
  vector<vector<vector<type>>> name( \
      h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...)       \
  vector<vector<vector<vector<type>>>> name( \
      a, vector<vector<vector<type>>>(       \
             b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))

#define rep1(a) for (ll _ = 0; _ < (ll)(a); ++_)
#define rep2(i, a) for (ll i = 0; i < (ll)(a); ++i)
#define rep3(i, a, b) for (ll i = a; i < (ll)(b); ++i)
#define rep4(i, a, b, c) for (ll i = a; i < (ll)(b); i += (c))
#define rrep1(a) for (ll i = (a)-1; i >= (ll)(0); --i)
#define rrep2(i, a) for (ll i = (a)-1; i >= (ll)(0); --i)
#define rrep3(i, a, b) for (ll i = (b)-1; i >= (ll)(a); --i)
#define rrep4(i, a, b, c) for (ll i = (b)-1; i >= (ll)(a); i -= (c))
#define overload4(a, b, c, d, e, ...) e
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)

#define all(x) (x).begin(),(x).end()
#define len(x) (ll)(x.size())
#define elif else if
#define bit(x, i) (((x)>>(i))&1)

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second

#define stoi stoll
#define abs llabs

#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define UNIQUE(x) \
  sort(all(x)), x.erase(unique(all(x)), x.end()), x.shrink_to_fit()

ll popcnt(ll x) { return __builtin_popcountll(x); }
ll popcnt(u64 x) { return __builtin_popcountll(x); }
ll popcnt_mod_2(ll x) { return __builtin_parityll(x); }
ll popcnt_mod_2(u64 x) { return __builtin_parityll(x); }
ll topbit(ll x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
ll topbit(u64 x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
ll lowbit(ll x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
ll lowbit(u64 x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }

template<typename T> T SUM(const vector<T> &A) {
  T s = 0; for (auto &&a: A) s += a;
  return s;
}

template<typename T> inline bool chmax(T &a, T b) {return ((a<b)?(a=b,true):(false));}
template<typename T> inline bool chmin(T &a, T b) {return ((a>b)?(a=b,true):(false));}

inline void wt(const char c) { cout << c; }
inline void wt(const string s) { cout << s; }
inline void wt(const char *s) { cout << s; }

template <typename T>
void wt_integer(T x) {
  if (x < 0) { cout << (i64)(x); }
  else { cout << (u64)(x); }
}
template <typename T>
void wt_real(T x) {
  cout << fixed << setprecision(15) << (long double)(x);
}

inline void wt(int x) { wt_integer(x); }
inline void wt(ll x) { wt_integer(x); }
inline void wt(i128 x) { wt_integer(x); }
inline void wt(u32 x) { wt_integer(x); }
inline void wt(u64 x) { wt_integer(x); }
inline void wt(u128 x) { wt_integer(x); }
inline void wt(double x) { wt_real(x); }
inline void wt(long double x) { wt_real(x); }
inline void wt(f128 x) { wt_real(x); }

template <class T, class U>
void wt(const pair<T, U> val) {
  wt(val.first); wt(' '); wt(val.second);
}
template <size_t N = 0, typename T>
void wt_tuple(const T t) {
  if constexpr (N < std::tuple_size<T>::value) {
    if constexpr (N > 0) { wt(' '); }
    const auto x = std::get<N>(t);
    wt(x);
    wt_tuple<N + 1>(t);
  }
}
template <class... T>
void wt(tuple<T...> tpl) {
  wt_tuple(tpl);
}
template <class T, size_t S>
void wt(const array<T, S> val) {
  auto n = val.size();
  for (size_t i = 0; i < n; i++) {
    if (i) wt(' ');
    wt(val[i]);
  }
}
template <class T>
void wt(const vector<T> val) {
  auto n = val.size();
  for (size_t i = 0; i < n; i++) {
    if (i) wt(' ');
    wt(val[i]);
  }
}

void print() { wt('\n'); }
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
  wt(head);
  if (sizeof...(Tail)) wt(' ');
  print(forward<Tail>(tail)...);
}

void YES(bool t = 1) { print(t ? "YES" : "NO"); }
void NO(bool t = 1) { YES(!t); }
void Yes(bool t = 1) { print(t ? "Yes" : "No"); }
void No(bool t = 1) { Yes(!t); }
void yes(bool t = 1) { print(t ? "yes" : "no"); }
void no(bool t = 1) { yes(!t); }
void onez(bool t = 1) { print(t ? 1 : 0); }
#define endl '\n'
#define dump(x) {cerr << #x " = " << x << '\n';}
#line 2 "main.cpp"

int solve();
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  while (!solve()) {break;}
  return 0;
}

int solve() {
  ll N;
  cin >> N;
  vi X(N+1), Y(N+1);
  rep(i, 1, N+1) cin >> X[i] >> Y[i];
  vi ag(N+1, 0);
  rep(i, 1, N+1) {
    ag[i] = ag[i-1];
    if (Y[i] == 0) {
      ag[i]++;
    } elif (Y[i] != X[i]+1) {
      if (ag[i-1]-ag[i-1-X[i]] >= Y[i]) ag[i]++;
    }
  }
  print(ag[N]);
  return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 14768
final_rank: 12

code_snippet: #include "bits/stdc++.h"

#define REP(i,num) for(ll i=0;i<(num);++i)
#define FOR(i,c,num) for(ll (i)=(c);(i)<(num);++(i))
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){ T x; cin >> x; return (x); }
template<typename T=ll,typename C=vector<T>>
C vecin(int N){ C x(N);REP(i,N){ x[i]=in<T>(); }return x; }
template<typename T=ll,size_t N>
array<T,N> arrin(){array<T,N> x;REP(i,N){ x[i]=in<T>(); }return x;}

void vout(){ cout << endl; }
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){ cout << ' ' << h;vout(forward<Tail>(t)...); }
void out(){ cout << endl; }
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){ cout << h;vout(forward<Tail>(t)...); }

template<typename T>
bool chmax(T& a,T b){ if(a<b){ a=b;return true; }return false; }
template<typename T>
bool chmin(T& a,T b){ if(a>b){ a=b;return true; }return false; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	auto N=in();
	vll S(N+1,0);
	REP(i,N){
		auto X=in(),Y=in();
		if(!Y){
			S[i+1]=S[i]+1;
		}
		else if(Y==X+1){
			S[i+1]=S[i];
		}
		else{
			auto Z=S[i]-S[i-X];
			if(Z>=Y) S[i+1]=S[i]+1;
			else S[i+1]=S[i];
		}
	}
	out(S[N]);
	return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 6936
final_rank: 6

code_snippet: /* -*- coding: utf-8 -*-
 *
 * 0731.cc: 投票 (Voting)
 */

#include<cstdio>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 500000;

/* typedef */

/* global variables */

int css[MAX_N + 1];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    int xi, yi;
    scanf("%d%d", &xi, &yi);

    int d = (yi == 0 || css[i] - css[max(0, i - xi)] >= yi) ? 1 : 0;
    css[i + 1] = css[i] + d;
  }

  printf("%d\n", css[n]);
  
  return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 4908
final_rank: 2

code_snippet: #include<iostream>
using namespace std;
int main(){
  
  int N;
  cin >> N;
  int X[N + 1] , Y[N + 1] , V[N + 1];
  
  for(int i = 0 ; i < N + 1 ; i++){
    V[i] = 0;    
  }
 
  
  for(int i = 1 ; i < N + 1 ; i++){
    cin >> X[i] >> Y[i];
    if(Y[i] == 0){
      V[i] = V[i - 1] + 1;
    }else if(Y[i] == V[i - 1] - V[i - 1 - X[i]] || Y[i] < V[i - 1] - V[i - 1 - X[i]] + 1){
      V[i] = V[i - 1] + 1;
    }else{
      V[i] = V[i - 1];
    }
  }
  

    cout << V[N] << endl;
      

}
accuracy: 1
time_ms: 210
memory_kb: 8992
final_rank: 14

code_snippet: #include <bits/stdc++.h>
#include <random>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
#define all(A) A.begin(),A.end()
#define ALL(A) A.begin(),A.end()
#define rep(i, n) for (ll i = 0; i < (ll) (n); i++)

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    ll N;
    cin>>N;
    vll S(N+1,0);
    rep(i,N){
        ll X,Y;
        cin>>X>>Y;
        if(Y==0){
            S[i+1]=S[i]+1;
        }
        else if(Y==X+1){
            S[i+1]=S[i];
        }
        else if(S[i]-S[i-X]>=Y)S[i+1]=S[i]+1;
        else S[i+1]=S[i];
    }
    cout<<S[N]<<endl;


}
accuracy: 1
time_ms: 50
memory_kb: 6964
final_rank: 7

code_snippet: #pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <sstream>
#include <utility>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <array>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}
inline double time() {
    return static_cast<double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> s(n+1);
    for(int i=1;i<=n;i++){
        int x,y; cin >> x >> y;
        int ad = (s[i-1]-s[i-1-x] >= y);
        s[i] = s[i-1] + ad;
    }
    cout << s[n] << endl;
}
accuracy: 1
time_ms: 50
memory_kb: 5188
final_rank: 3

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define BIG_NUM 2000000000
#define HUGE_NUM 4000000000000000000 //オーバーフローに注意
#define MOD 1000000007
#define EPS 0.000000001



#define SIZE 500005

int A[SIZE];

int main(){

	int N;
	scanf("%d",&N);

	int X,Y;
	int sumOK = 0;

	for(int i = 1; i <= N; i++){

		scanf("%d %d",&X,&Y);

		int R = A[i-1];
		int L = A[i-X-1];

		int numOK = R-L;
		if(numOK >= Y){

			sumOK++;

		}
		A[i] = sumOK;
	}

	printf("%d\n",sumOK);

	return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 5180
final_rank: 4

code_snippet: #line 1 "a.cpp"
#define PROBLEM ""
#line 2 "/home/kuhaku/home/github/algo/lib/template/template.hpp"
#pragma GCC target("sse4.2,avx2,bmi2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
template <class T, class U>
bool chmax(T &a, const U &b) {
    return a < (T)b ? a = (T)b, true : false;
}
template <class T, class U>
bool chmin(T &a, const U &b) {
    return (T)b < a ? a = (T)b, true : false;
}
constexpr std::int64_t INF = 1000000000000000003;
constexpr int Inf = 1000000003;
constexpr int MOD = 1000000007;
constexpr int MOD_N = 998244353;
constexpr double EPS = 1e-7;
constexpr double PI = M_PI;
#line 3 "/home/kuhaku/home/github/algo/lib/math/pow.hpp"

std::int64_t safe_mod(std::int64_t a, std::int64_t mod) {
    a %= mod;
    return a >= 0 ? a : a + mod;
}

std::int64_t pow_int(std::int64_t a, std::int64_t n) {
    assert(n >= 0);
    std::int64_t res = 1, mul = a;
    for (; n > 0; n >>= 1) {
        if (n & 1) res *= mul;
        mul *= mul;
    }
    return res;
}

std::int64_t inv_mod(std::int64_t a, std::int64_t mod) {
    std::int64_t b = mod, u = 1, v = 0, t;
    while (b > 0) {
        t = a / b;
        std::swap(a -= t * b, b);
        std::swap(u -= t * v, v);
    }
    return u >= 0 ? u % mod : (mod - (-u) % mod) % mod;
}

std::int64_t pow_mod(std::int64_t a, std::int64_t n, std::int64_t mod) {
    if (n < 0) return inv_mod(pow_mod(a, -n, mod), mod);
    std::int64_t res = 1, mul = safe_mod(a, mod);
    for (; n > 0; n >>= 1) {
        if (n & 1) (res *= mul) %= mod;
        (mul *= mul) %= mod;
    }
    return res;
}

int ceil_pow2(std::int64_t n) {
    int x = 0;
    while ((std::uint64_t(1) << x) < (std::uint64_t)(n)) ++x;
    return x;
}

int floor_pow2(std::int64_t n) {
    int x = 0;
    while ((std::uint64_t(1) << (x + 1)) <= (std::uint64_t)(n)) ++x;
    return x;
}
#line 3 "/home/kuhaku/home/github/algo/lib/segment_tree/monoid.hpp"

template <class T>
struct Add {
    using value_type = T;
    static constexpr T id = T(0);
    static constexpr T op(const T &lhs, const T &rhs) { return lhs + rhs; }

    template <class U>
    static constexpr U f(T lhs, U rhs) {
        return lhs + rhs;
    }
};

template <class T>
struct And {
    using value_type = T;
    static constexpr T id = std::numeric_limits<T>::max();
    static constexpr T op(const T &lhs, const T &rhs) { return lhs & rhs; }

    template <class U>
    static constexpr U f(T lhs, U rhs) {
        return lhs & rhs;
    }
};

template <class T>
struct Or {
    using value_type = T;
    static constexpr T id = T(0);
    static constexpr T op(const T &lhs, const T &rhs) { return lhs | rhs; }

    template <class U>
    static constexpr U f(T lhs, U rhs) {
        return lhs | rhs;
    }
};

template <class T>
struct Xor {
    using value_type = T;
    static constexpr T id = T(0);
    static constexpr T op(const T &lhs, const T &rhs) { return lhs ^ rhs; }

    template <class U>
    static constexpr U f(T lhs, U rhs) {
        return lhs ^ rhs;
    }
};

template <class T>
struct Min {
    using value_type = T;
    static constexpr T id = std::numeric_limits<T>::max();
    static constexpr T op(const T &lhs, const T &rhs) { return std::min(lhs, rhs); }

    template <class U>
    static constexpr U f(T lhs, U rhs) {
        return std::min((U)lhs, rhs);
    }
};

template <class T>
struct Max {
    using value_type = T;
    static constexpr T id = std::numeric_limits<T>::min();
    static constexpr T op(const T &lhs, const T &rhs) { return std::max(lhs, rhs); }

    template <class U>
    static constexpr U f(T lhs, U rhs) {
        return std::max((U)lhs, rhs);
    }
};

template <class T>
struct Update {
    using value_type = T;
    static constexpr T id = std::numeric_limits<T>::max();
    static constexpr T op(const T &lhs, const T &rhs) { return lhs == Update::id ? rhs : lhs; }

    template <class U>
    static constexpr U f(T lhs, U rhs) {
        return lhs == Update::id ? rhs : lhs;
    }
};

template <class T>
struct Affine {
    using value_type = std::pair<T, T>;
    static constexpr std::pair<T, T> id = std::pair<T, T>(1, 0);
    static constexpr std::pair<T, T> op(std::pair<T, T> lhs, std::pair<T, T> rhs) {
        return {lhs.first * rhs.first, lhs.first * rhs.second + lhs.second};
    }
};

template <class M>
struct Rev {
    using T = typename M::value_type;
    using value_type = T;
    static constexpr T id = M::id;
    static constexpr T op(T lhs, T rhs) { return M::op(rhs, lhs); }
};
#line 5 "/home/kuhaku/home/github/algo/lib/segment_tree/segment_tree.hpp"

/**
 * @brief セグメント木
 * @see https://noshi91.hatenablog.com/entry/2020/04/22/212649
 *
 * @tparam M モノイド
 */
template <class M>
struct segment_tree {
  private:
    using T = typename M::value_type;

  public:
    segment_tree() : segment_tree(0) {}
    explicit segment_tree(int n, T e = M::id) : segment_tree(std::vector<T>(n, e)) {}
    template <class U>
    explicit segment_tree(const std::vector<U> &v) : _n(v.size()) {
        this->_log = ceil_pow2(this->_n);
        this->_size = 1 << this->_log;
        this->data = std::vector<T>(this->_size << 1, M::id);
        for (int i = 0; i < this->_n; ++i) this->data[this->_size + i] = T(v[i]);
        for (int i = this->_size - 1; i >= 1; --i) this->update(i);
    }

    const T &operator[](int k) const { return this->data[k + this->_size]; }
    T at(int k) const { return this->operator[](k); }
    T get(int k) const { return this->operator[](k); }

    void set(int k, T val) {
        assert(0 <= k && k < this->_n);
        k += this->_size;
        this->data[k] = val;
        for (int i = 1; i <= this->_log; ++i) this->update(k >> i);
    }
    void reset(int k) { this->set(k, M::id); }

    T all_prod() const { return this->data[1]; }
    T prod(int a, int b) const {
        assert(0 <= a && b <= this->_n);
        T l = M::id, r = M::id;
        for (a += this->_size, b += this->_size; a < b; a >>= 1, b >>= 1) {
            if (a & 1) l = M::op(l, this->data[a++]);
            if (b & 1) r = M::op(this->data[--b], r);
        }
        return M::op(l, r);
    }

    template <class F>
    int max_right(F f) const {
        return this->max_right(0, f);
    }

    template <class F>
    int max_right(int l, F f) const {
        assert(0 <= l && l <= this->_n);
        assert(f(M::id));
        if (l == this->_n) return this->_n;
        l += this->_size;
        T sm = M::id;
        do {
            while (l % 2 == 0) l >>= 1;
            if (!f(M::op(sm, this->data[l]))) {
                while (l < this->_size) {
                    l = (2 * l);
                    if (f(M::op(sm, this->data[l]))) {
                        sm = M::op(sm, this->data[l]);
                        l++;
                    }
                }
                return l - this->_size;
            }
            sm = M::op(sm, this->data[l]);
            l++;
        } while ((l & -l) != l);
        return this->_n;
    }

    int max_right(T x) const { return this->max_right(0, x); }

    int max_right(int l, T x) const {
        return this->max_right(l, [&x](auto y) {
            return !(y < x);
        });
    }

    template <class F>
    int min_left(F f) const {
        return this->min_left(this->_n, f);
    }

    template <class F>
    int min_left(int r, F f) const {
        assert(0 <= r && r <= this->_n);
        assert(f(M::id));
        if (r == 0) return 0;
        r += this->_size;
        T sm = M::id;
        do {
            r--;
            while (r > 1 && (r % 2)) r >>= 1;
            if (!f(M::op(this->data[r], sm))) {
                while (r < this->_size) {
                    r = (2 * r + 1);
                    if (f(M::op(this->data[r], sm))) {
                        sm = M::op(this->data[r], sm);
                        r--;
                    }
                }
                return r + 1 - this->_size;
            }
            sm = M::op(this->data[r], sm);
        } while ((r & -r) != r);
        return 0;
    }

    int min_left(T x) const { return this->min_left(this->_n, x); }

    int min_left(int r, T x) const {
        return this->min_left(r, [&x](auto y) {
            return !(y < x);
        });
    }

  private:
    int _n, _size, _log;
    std::vector<T> data;

    void update(int k) { this->data[k] = M::op(this->data[2 * k], this->data[2 * k + 1]); }
};
#line 3 "/home/kuhaku/home/github/algo/lib/template/macro.hpp"
#define FOR(i, m, n) for (int i = (m); i < int(n); ++i)
#define FORR(i, m, n) for (int i = (m)-1; i >= int(n); --i)
#define FORL(i, m, n) for (int64_t i = (m); i < int64_t(n); ++i)
#define rep(i, n) FOR (i, 0, n)
#define repn(i, n) FOR (i, 1, n + 1)
#define repr(i, n) FORR (i, n, 0)
#define repnr(i, n) FORR (i, n + 1, 1)
#define all(s) (s).begin(), (s).end()
#line 3 "/home/kuhaku/home/github/algo/lib/template/sonic.hpp"
struct Sonic {
    Sonic() {
        std::ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
    }

    constexpr void operator()() const {}
} sonic;
#line 5 "/home/kuhaku/home/github/algo/lib/template/atcoder.hpp"
using namespace std;
using ll = std::int64_t;
using ld = long double;
template <class T, class U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
    return is >> p.first >> p.second;
}
template <class T>
std::istream &operator>>(std::istream &is, std::vector<T> &v) {
    for (T &i : v) is >> i;
    return is;
}
template <class T, class U>
std::ostream &operator<<(std::ostream &os, const std::pair<T, U> &p) {
    return os << '(' << p.first << ',' << p.second << ')';
}
template <class T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &v) {
    for (auto it = v.begin(); it != v.end(); ++it) {
        os << (it == v.begin() ? "" : " ") << *it;
    }
    return os;
}
template <class Head, class... Tail>
void co(Head &&head, Tail &&...tail) {
    if constexpr (sizeof...(tail) == 0) std::cout << head << '\n';
    else std::cout << head << ' ', co(std::forward<Tail>(tail)...);
}
template <class Head, class... Tail>
void ce(Head &&head, Tail &&...tail) {
    if constexpr (sizeof...(tail) == 0) std::cerr << head << '\n';
    else std::cerr << head << ' ', ce(std::forward<Tail>(tail)...);
}
template <typename T, typename... Args>
auto make_vector(T x, int arg, Args... args) {
    if constexpr (sizeof...(args) == 0) return std::vector<T>(arg, x);
    else return std::vector(arg, make_vector<T>(x, args...));
}
void setp(int n) {
    std::cout << std::fixed << std::setprecision(n);
}
void Yes(bool is_correct = true) {
    std::cout << (is_correct ? "Yes" : "No") << '\n';
}
void No(bool is_not_correct = true) {
    Yes(!is_not_correct);
}
void YES(bool is_correct = true) {
    std::cout << (is_correct ? "YES" : "NO") << '\n';
}
void NO(bool is_not_correct = true) {
    YES(!is_not_correct);
}
void Takahashi(bool is_correct = true) {
    std::cout << (is_correct ? "Takahashi" : "Aoki") << '\n';
}
void Aoki(bool is_not_correct = true) {
    Takahashi(!is_not_correct);
}
#line 4 "a.cpp"

int main(void) {
    int n;
    cin >> n;
    segment_tree<Add<int>> st(n);
    rep (i, n) {
        int x, y;
        cin >> x >> y;
        if (st.prod(i - x, i) >= y)
            st.set(i, 1);
    }
    cout << st.all_prod() << endl;

    return 0;
}
accuracy: 1
time_ms: 100
memory_kb: 9088
final_rank: 10

code_snippet: #include <bits/extc++.h>

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) begin(x),end(x)
#define Fixed fixed << setprecision(12)
#define updiv(a, b) (((a) + (b) - 1) / (b))
using pii = pair<int,int>;
constexpr int32_t INF  = 0x3f3f3f3f;
constexpr int_fast64_t LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7;
constexpr int mod2 = 998244353;

template <class Func>
class FixPoint : Func {
public:
    explicit constexpr FixPoint(Func&& f) noexcept : Func(forward<Func>(f)) {}

    template <class... Args>
    constexpr decltype(auto) operator()(Args&&... args) const {
        return Func::operator()(*this, std::forward<Args>(args)...);
    }
};

template <class Func>
static inline constexpr decltype(auto) makeFixPoint(Func&& f) noexcept {
    return FixPoint<Func>{forward<Func>(f)};
}

template<class T, class U> istream& operator>>(istream& is, pair<T, U>& p){ is >> p.first >> p.second; return (is); }
template<class T, class U> ostream& operator<<(ostream& os, pair<T, U>& p){ os << p.first << ' ' << p.second; return (os); }
template<class T> istream& operator>>(istream& is, vector<T>& v){ for (auto &&e : v) is >> e; return (is); }
template<class T> ostream& operator<<(ostream& os, vector<T>& v){ for (auto &&e : v) os << e << ' '; return (os); }

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using max_heap = priority_queue<T>;
template <class T> using min_heap = priority_queue<T, vector<T>, greater<T> >;
template <class A, class B> using umap = unordered_map<A, B>;
template <class T> using uset = unordered_set<T>;

template <class T> using Max_Heap = __gnu_pbds::priority_queue<T, less<T>, __gnu_pbds::rc_binomial_heap_tag>;
template <class T> using Min_Heap = __gnu_pbds::priority_queue<T, greater<T>, __gnu_pbds::rc_binomial_heap_tag>;
template <class T> using Set = __gnu_pbds::tree<T, __gnu_pbds::null_type, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
template <class K, class V> using Umap = __gnu_pbds::gp_hash_table<K, V>;
template <class T> using Rope = __gnu_cxx::rope<T>;
using Trie = __gnu_pbds::trie<string, __gnu_pbds::null_type, __gnu_pbds::trie_string_access_traits<>, __gnu_pbds::pat_trie_tag, __gnu_pbds::trie_prefix_search_node_update>;

template <class T> void bye(T x){ cout << x << '\n'; exit(0); }
inline int square(int a){ return (a * a); }

constexpr int dx[] = {1,0,-1,0,1,1,-1,-1};
constexpr int dy[] = {0,-1,0,1,1,-1,-1,1};

signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout.setf(ios_base::fixed);
    cout.precision(12);

    int n;
    cin >> n;

    assert(1 <= n && n <= 500000);

    vector<int> x(n), y(n);

    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> y[i];
        assert(0 <= x[i] && x[i] <= i);
        assert(0 <= y[i] && y[i] <= x[i] + 1);
    }

    vector<int> cum(n + 1);

    for (int i = 1; i <= n; ++i) {
        if (cum[i - 1] - cum[max(0, i - x[i - 1] - 1)] >= y[i - 1]) {
            cum[i] = 1;
        }
        cum[i] += cum[i - 1];
    }

    cout << cum[n] << '\n';

    return (0);
}
accuracy: 1
time_ms: 50
memory_kb: 8892
final_rank: 9

code_snippet: #include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define drep(i,j,n) for(int i=0;i<(int)(n-1);i++)for(int j=i+1;j<(int)(n);j++)
#define trep(i,j,k,n) for(int i=0;i<(int)(n-2);i++)for(int j=i+1;j<(int)(n-1);j++)for(int k=j+1;k<(int)(n);k++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yes(ans) if(ans)printf("yes\n");else printf("no\n")
#define Yes(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YES(ans) if(ans)printf("YES\n");else printf("NO\n")
#define popcount(v) __builtin_popcountll(v)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
#define vector4d(type,name,h,w,d,...) vector<vector<vector<vector<type>>>>name(h,vector<vector<vector<type>>>(w,vector<vector<type>>(d,vector<type>(__VA_ARGS__))))
using namespace std;
using ll = long long;
template<class T> using rpriority_queue = priority_queue<T, vector<T>, greater<T>>;
const int MOD=1000000007;
const int MOD2=998244353;
const int INF=1<<30;
const ll INF2=1LL<<60;
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);}
template<class T,class U,class V>void scan(tuple<T,U,V>& p){scan(get<0>(p));scan(get<1>(p));scan(get<2>(p));}
template<class T, size_t size> void scan(array<T, size>& a){ for(auto&& i : a) scan(i);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll modinv(ll a, ll m) {ll b = m, u = 1, v = 0;while (b) {ll t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}
ll updivide(ll a,ll b){return (a+b-1)/b;}
int msb(ll v){return 63-__builtin_clzll(v);}
template<class T> void chmax(T &a,const T b){if(b>a)a=b;}
template<class T> void chmin(T &a,const T b){if(b<a)a=b;}


template <class T> struct fenwick_tree {
    using U = T;

  public:
    fenwick_tree() : _n(0) {}
    fenwick_tree(int n) : _n(n), data(n) {}

    void add(int p, T x) {
        assert(0 <= p && p < _n);
        p++;
        while (p <= _n) {
            data[p - 1] += U(x);
            p += p & -p;
        }
    }

    T sum(int l, int r) {
        assert(0 <= l && l <= r && r <= _n);
        return sum(r) - sum(l);
    }

  private:
    int _n;
    std::vector<U> data;

    U sum(int r) {
        U s = 0;
        while (r > 0) {
            s += data[r - 1];
            r -= r & -r;
        }
        return s;
    }
};

int main(){
    INT(n);
    fenwick_tree<int> fw(n);
    for(int i=0;i<n;i++){
        INT(x,y);
        if(fw.sum(i-x,i)>=y)fw.add(i,1);
    }
    out(fw.sum(0,n));
}
accuracy: 1
time_ms: 70
memory_kb: 4924
final_rank: 5