Submission #925201

#TimeUsernameProblemLanguageResultExecution timeMemory
92520112345678Potatoes and fertilizers (LMIO19_bulves)C++17
24 / 100
79 ms12284 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int nx=5e5+5; ll n, a[nx], b[nx], ans; int main() { cin.tie(NULL)->sync_with_stdio(false); cin>>n; for (int i=1; i<=n; i++) cin>>a[i]>>b[i]; ll i=1, j=1; while (i<=n&&j<=n) { ll mn=min(a[i], b[j]); a[i]-=mn; b[j]-=mn; ans+=mn*abs(i-j); if (a[i]==0) i++; if (b[j]==0) j++; } cout<<ans; }
#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...