This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define pb push_back
#define int long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long int>
#define vvll vector<vector<long long int>>
#define pii pair<int, int>
#define vpii vector<pair<int, int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define mii map<int,int>
#define mll map<long long int, long long int>
#define mivi map<int,vector<int>>
#define f0r(i,n) for(int i=0;i<n;i++)
#define FOR(i,k,n) for(int i=k;i<n;i++)
using namespace std;
const int mxn = 1005;
vi adj[mxn];
signed main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
//ifstream cin(".in");
//ofstream cout(".out");
int n;
cin>>n;
vi l(n);
vi r(n);
f0r(i, n)cin>>l[i]>>r[i];
int dp[n];
dp[0] = 1;
vi b(n+1, 4e18);
b[0] = -1;
//b[1] = 0;
vi todo[2*n+5];
todo[r[0] + 1].pb(0);
FOR(i, 1, n){
for(auto u : todo[i])b[dp[u]] = min(u, b[dp[u]]);
int lo = 0;
int hi = n;
while(lo < hi){
int mid = lo + (hi - lo + 1)/2;
if(b[mid] < i - l[i]){
lo = mid;
}
else hi = mid - 1;
}
dp[i] = lo + 1;
todo[i + r[i] + 1].pb(i);
}
//f0r(i, n)cout<<dp[i]<<' ';
//cout<<'\n';
int ans = 0;
f0r(i, n)ans = max(ans, dp[i]);
cout<<ans;
}
# | 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... |