Submission #513861

#TimeUsernameProblemLanguageResultExecution timeMemory
513861blueSjeckanje (COCI21_sjeckanje)C++17
55 / 110
2045 ms5632 KiB
#include <iostream> using namespace std; using ll = long long; ll* a; bool cmp(int i, int j) { if(a[i] != a[j]) return a[i] < a[j]; else return i < j; } const ll INF = 1'000'000'000'000'000'000LL; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, q; cin >> n >> q; a = new ll[1+n+1]; for(int i = 1; i <= n; i++) cin >> a[i]; a[0] = a[n+1] = 0; for(int j = 1; j <= q; j++) { ll l, r, x; cin >> l >> r >> x; for(int i = l; i <= r; i++) a[i] += x; ll dp[1+n]; dp[0] = 0; ll mx1 = -INF, mx2 = -INF; for(int i = 1; i <= n; i++) { mx1 = max(mx1, dp[i-1] - a[i]); mx2 = max(mx2, dp[i-1] + a[i]); dp[i] = max(mx1 + a[i], mx2 - a[i]); } cout << dp[n] << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...