Submission #925200

#TimeUsernameProblemLanguageResultExecution timeMemory
92520012345678Potatoes and fertilizers (LMIO19_bulves)C++17
0 / 100
68 ms14968 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]; int i=1, j=1; while (i<=n&&j<=n) { int 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...