Submission #1091522

#TimeUsernameProblemLanguageResultExecution timeMemory
1091522vjudge1Potatoes and fertilizers (LMIO19_bulves)C++17
34 / 100
57 ms9044 KiB
#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); } 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 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...