#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update> oset;
void setIo(string in="", string out=""){
if (!in.empty() && !out.empty()){
freopen(in.c_str(), "r", stdin);
freopen(out.c_str(), "w", stdout);
}
ios::sync_with_stdio(false);
cin.tie(0);
}
#define all(c) (c).begin(), (c).end()
#define sz(c) (int)(c).size()
#define vt vector
#define pb push_back
#define F first
#define S second
#define pii pair<int, int>
#define DEBUG true
#define dbg(x) if (DEBUG) cout << #x << " = " << x << ";\n";
#define dbg_vec(v) if (DEBUG) cout << #v << " = { "; for (auto x: v) cout << x << " "; cout << "}\n";
#define mp make_pair
template <typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
return os << "(" << p.first << ", " << p.second << ")";
}
class segtree {
private:
struct node {
ll x;
};
node single(ll v){
return {v};
}
node merge(node a, node b){
return single(a.x + b.x);
}
int size;
vector<node> arr;
node fill = single(0ll);
node neutral = single(0ll);
void set(int i, ll v, int x, int lx, int rx){
if (rx - lx == 1){
arr[x] = single(v);
return;
}
int m = (lx+rx)/2;
if (i < m){
set(i, v, 2*x+1, lx, m);
} else {
set(i, v, 2*x+2, m, rx);
}
arr[x] = merge(arr[2*x+1], arr[2*x+2]);
}
node query(int l, int r, int x, int lx, int rx){
if (l >= rx || r <= lx) return neutral;
if (l <= lx && rx <= r) return arr[x];
int m = (lx+rx)/2;
node s1 = query(l, r, 2*x+1, lx, m);
node s2 = query(l, r, 2*x+2, m, rx);
return merge(s1,s2);
}
public:
void init(int n) {size = 1;while(size < n) size *= 2;arr.assign(2*size, fill);}
void set(int i, ll v) {return set(i, v, 0, 0, size);}
node query(int l, int r) {return query(l, r, 0, 0, size);}
};
void solve(){
int n; cin>>n;
segtree st;
st.init(n);
vt<pair<ll, ll>> A(n);
for (int i=0;i<n;i++){
cin>>A[i].F>>A[i].S;
}
/*
Summary
dp[i] = max(dp[j]+1) for j + max(lj, ri) < i
Let's restrict j to the interval [O, i-ri-1]
Now dp[i] = max(dp[j]+1) for j+lj < i
*/
vt<ll> dp(n, 1);
for (int i=1;i<n;i++){
for (int j=0;j+A[i].F<i;j++){
if (j+A[j].S < i) dp[i] = max(dp[i], dp[j]+1);
}
}
/*
vt<pair<ll,ll>> dp(n,mp(1,1));
for (int i=1;i<n;i++){
for (int j=0;j+A[i].F<i;j++){
if (j+A[j].S < i) {
dp[i].F = max(dp[i].F, dp[j].F+1);
}
}
dp[i].S = max(dp[i].F, dp[i-1].F);
}
*/
//cout << endl;
//dbg_vec(dp)
cout << *max_element(all(dp)) << endl;
}
int main() {
setIo();
int tt=1;
// cin>>tt;
while(tt--) solve();
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'void setIo(std::string, std::string)':
Main.cpp:12:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | freopen(in.c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:13:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | freopen(out.c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |