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>
using namespace std;
vector<pair<long long,long long>> v;
long long per[10000001] , suf[10000001];
int main() {
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
long long n;cin>>n;
for(int i = 0;i<n;i++){
long long a,b;
cin>>a>>b;
v.push_back({a,b});
}
per[0] = v[0].first+v[0].second;
suf[n-1] = v[n-1].second-v[n-1].first;
for(int i = 1;i<n;i++){
per[i] = max(per[i-1],v[i].first+v[i].second);
}for(int i = n-2;i>=0;i--){
suf[i] = max(suf[i+1],v[i].second-v[i].first);
}
long long ans = 0;
for(int i = 0;i<n;i++){
if(i==0){
if(suf[i+1]<v[i].second-v[i].first){
ans++;
}
}else if(i==n-1){
if(per[i-1]<v[i].first+v[i].second)ans++;
}else{
if(suf[i+1]<v[i].second-v[i].first&&per[i-1]<v[i].first+v[i].second)ans++;
}
}
cout<<ans<<"\n";
return 0;
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |