Submission #146934

#TimeUsernameProblemLanguageResultExecution timeMemory
146934BruteforcemanPotatoes and fertilizers (LMIO19_bulves)C++11
24 / 100
133 ms12152 KiB
#include "bits/stdc++.h" using namespace std; typedef pair <int, int> pii; int a[1000010], b[1000010]; long long pre[1000010], suf[1000010]; int main(int argc, char const *argv[]) { ios_base :: sync_with_stdio (false); cin.tie (0); int n; cin >> n; for(int i = 1; i <= n; i++) { cin >> a[i] >> b[i]; } for(int i = 1; i <= n; i++) { pre[i] = pre[i - 1] + a[i] - b[i]; } for(int i = n; i >= 1; i--) { suf[i] = suf[i + 1] + a[i] - b[i]; } long long ans = 0; for(int i = 1; i < n; i++) { if(pre[i] < 0) { ans -= pre[i]; } if(suf[i + 1] < 0) { ans -= suf[i + 1]; } } cout << ans << endl; 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...