Submission #1152620

#TimeUsernameProblemLanguageResultExecution timeMemory
1152620YSH2020Sjeckanje (COCI21_sjeckanje)C++20
0 / 110
1 ms320 KiB
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { int n; cin >> n; int q; cin >> q; int a[n]; for (int i = 0; i < n; i++ )cin >> a[i]; int d[n]; for (int i = 0; i < n-1; i++) d[i] = a[i+1]-a[i]; d[n-1] = 0; while (q--) { int s, e, c; cin >> s >> e >> c; if (s >= 2) d[s-2]+=c; d[e-1]-= c; int ans = 0; int cur = d[0]; //two cases: take first, dont take first for (int i = 1; i < n-1; i++) { if (abs(cur+d[i]) > abs(cur)) { //take it cur += d[i]; } else { ans += abs(cur); cur = 0; } } ans += abs(cur); //case 2: dont take first int ans2 = 0; cur = 0; for (int i = 1; i < n-1; i++) { if (abs(cur+d[i]) > abs(cur)) { cur += d[i]; } else { ans2 += abs(cur); cur = 0; } }ans2 += abs(cur); cout << max(ans, ans2) << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...