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 <cstdlib>
#include <iostream>
#include <vector>
int main() {
std::cin.tie(NULL)->sync_with_stdio(false);
int n;
std::cin >> n;
std::vector<int> diff(n);
long long ans = 0;
long long total = 0;
for (int i = 0; i < n; i++) {
int a, b;
std::cin >> a >> b;
total += a - b;
diff[i] = total > 0 ? -1 : 1;
ans += std::abs(total);
}
std::cerr << "a: " << ans << std::endl;
std::cerr << "D:"; for (int x: diff) std::cerr << " " << x; std::cerr << std::endl;
if (total == 1) {
long long current = ans, total_diff = 0;
while (!diff.empty()) {
total_diff += diff.back();
diff.pop_back();
ans = std::min(ans, current + total_diff);
}
}
std::cout << ans << std::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... |