Submission #477341

#TimeUsernameProblemLanguageResultExecution timeMemory
477341BTheroPotatoes and fertilizers (LMIO19_bulves)C++17
0 / 100
1084 ms976 KiB
#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 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...