Submission #1135937

#TimeUsernameProblemLanguageResultExecution timeMemory
1135937iancu007Potatoes and fertilizers (LMIO19_bulves)C++20
0 / 100
169 ms6220 KiB
#include <iostream> #include <cmath> int a[500005], b[500005], d[500005]; using namespace std; long long solve(int n) { for (int i=1; i<=n; i++) d[i]=a[i]-b[i]; long long ans=0; for (int i=1; i<=n-1; i++) if (d[i]) { ans+=abs(d[i]); d[i+1]+=d[i]; d[i] = 0; } return ans; } int main() { int n; cin>>n; for (int i=1; i<=n; i++) cin>>a[i]>>b[i]; cout<<solve(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...