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>
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
typedef long long ll;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<int> a(n), b(n);
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
}
ll ans = 0;
for (int i = 0; i + 1 < n; i++) {
ll x = 0, y = 0;
for (int j = 0; j <= i; j++) {
x += a[j];
x -= b[j];
}
for (int j = i + 1; j < n; j++) {
y += a[j];
y -= b[j];
}
if (x >= 0 && y >= 0) {
// ignore
}
else if (x >= 0 && y < 0) {
ans += -y;
}
else if (x < 0 && y >= 0) {
ans += -x;
}
else {
assert(0);
}
}
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... |