#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define pb push_back
#define sz(a) (ll) a.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, a, b) for(ll i=a; i<b; i++)
#define rrep(i, a, b) for(ll i=a; i>=b; i--)
#define vl vector<ll>
#define vpll vector<pair<ll, ll>>
#define vvl vector<vector<ll>>
#define pll pair<ll, ll>
ll n;
vl l, r, best, dp;
void f() {
cin >> n;
l.resize(n);
r.resize(n);
best.assign(n, 0);
dp.assign(n, 0);
rep(i, 0, n) cin >> l[i] >> r[i];
dp[0]=1;
best[0]=1;
rep(i, 1, n){
dp[i]=1;
if(i-l[i]>=0){
dp[i]+=best[i-l[i]];
}
if(l[i]==0){
dp[i]=max(dp[i], 1+best[i-1]);
}
best[i]=max(dp[i], best[i-1]);
}
cout << best[n-1];
}
int main() {
int tc = 1;
// cin >> tc;
for (int i = 1; i <= tc; i++) {
// cout << '#' << i << endl;
f();
// if (i != tc) cout << 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... |