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;
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 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... |