Submission #950905

#TimeUsernameProblemLanguageResultExecution timeMemory
950905daoquanglinh2007Potatoes and fertilizers (LMIO19_bulves)C++17
0 / 100
1 ms2396 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int NM = 5e5; int N, a[NM+5], b[NM+5], ans = 0; signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N; for (int i = 1; i <= N; i++){ cin >> a[i] >> b[i]; } for (int i = 2; i <= N; i++) if (a[i-1] > b[i-1]){ ans += a[i-1]-b[i-1]; a[i] += a[i-1]-b[i-1]; a[i-1] = b[i-1]; } for (int i = N-1; i >= 1; i--) if (a[i+1] > b[i+1]){ ans += a[i+1]-b[i+1]; a[i] += a[i+1]-b[i+1]; a[i+1] = b[i+1]; } cout << ans; 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...