# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
891414 | ClHg2 | Potatoes and fertilizers (LMIO19_bulves) | C++14 | 69 ms | 16984 KiB |
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 EVAL(x) #x " = " << (x)
using std::cin;
using std::cout;
using i64 = int64_t;
auto main() -> int {
std::ios_base::sync_with_stdio(false);
cin.tie(nullptr);
auto n = 0;
cin >> n;
auto a = std::vector<int>(n);
for (auto i = 0; i < n; ++i) {
auto x = 0, y = 0;
cin >> x >> y;
a[i] = x - y;
}
auto pre = std::vector<i64>(n + 1);
for (auto i = 0; i < n; ++i) pre[i + 1] = pre[i] + a[i];
auto suf = std::vector<i64>(n + 1);
for (auto i = n - 1; ~i; --i) suf[i] = suf[i + 1] + a[i];
auto ans = i64{0};
for (auto i = 1; i < n; ++i) {
if (pre[i] < 0)
ans -= pre[i];
else if (suf[i] < 0)
ans -= suf[i];
}
cout << ans << "\n";
}
Compilation message (stderr)
# | 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... |