# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1164826 | Ghulam_Junaid | Potatoes and fertilizers (LMIO19_bulves) | C++20 | 48 ms | 4168 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 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... |