Submission #1164826

#TimeUsernameProblemLanguageResultExecution timeMemory
1164826Ghulam_JunaidPotatoes and fertilizers (LMIO19_bulves)C++20
24 / 100
48 ms4168 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 5e5 + 100; int n, a[N], b[N]; int main(){ ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 1; i <= n; i ++) cin >> a[i] >> b[i]; int p1 = 1, p2 = 1; ll ans = 0; while (p1 <= n and p2 <= n){ if (a[p1] < b[p2]){ ans += 1ll * a[p1] * abs(p2 - p1); b[p2] -= a[p1]; p1++; } else{ ans += 1ll * b[p2] * abs(p2 - p1); a[p1] -= b[p2]; p2++; } } cout << ans << endl; }
#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...