Submission #547191

#TimeUsernameProblemLanguageResultExecution timeMemory
547191Ahmed57Lightning Rod (NOI18_lightningrod)C++14
80 / 100
2076 ms255632 KiB
#include<bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); int n;cin>>n; int per[n] , suf[n]; int aa[n], bb[n]; for(int i = 0;i<n;i++){ cin>>aa[i]>>bb[i]; } per[0] = aa[0]+bb[0]; suf[n-1] = bb[n-1]-aa[n-1]; for(int i = 1;i<n;i++){ per[i] = max(per[i-1],aa[i]+bb[i]); }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...