Submission #547193

#TimeUsernameProblemLanguageResultExecution timeMemory
547193Ahmed57Lightning Rod (NOI18_lightningrod)C++14
100 / 100
1720 ms262144 KiB
#include<bits/stdc++.h> using namespace std; const int N = 1e7+9; int per[N] , suf[N]; int aa[N], bb[N]; int main() { ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); int n;cin>>n; for(int i = 0;i<n;i++){ cin>>aa[i]>>bb[i]; if(i==0){ per[0] = aa[0]+bb[0]; }else{ per[i] = max(per[i-1],aa[i]+bb[i]); } } suf[n-1] = bb[n-1]-aa[n-1]; for(int i = n-2;i>=0;i--){ suf[i] = max(suf[i+1],bb[i]-aa[i]); } int ans = 0; for(int i = 0;i<n;i++){ if(i==0){ if(suf[i+1]<bb[i]-aa[i]){ ans++; } }else if(i==n-1){ if(per[i-1]<aa[i]+bb[i])ans++; }else{ if(suf[i+1]<bb[i]-aa[i]&&per[i-1]<aa[i]+bb[i])ans++; } } cout<<ans<<"\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...