#include <bits/stdc++.h>
using namespace std;
vector<int>v;
int f[200005];
int dp(int n){
    
    if(f[n]==-1){
        int x=0;
        for(int so=0;so<n-v[n];so++){
            if(f[so]==-1){dp(so);}
            x=max(x,f[so]);
         
        }
        f[n]=x+1;
    }
   // cout<<f[n]<<" "<<n<<endl;
    
    return f[n];
}
int main() {
int n;
cin>>n;
int x,y;
int ans=n;
while(n--){
   
    cin>>x>>y;
     v.push_back(x);
}
for(int so=0;so<=ans;so++){
    f[so]=-1;
}
f[0]=1;
dp(ans-1);
int an=0;
for(int so=0;so<ans;so++){
 if(f[so]==-1){dp(so);}
 an=max(an,f[so]);
}
cout<<an<<endl;
}
| # | 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... |