Submission #375187

#TimeUsernameProblemLanguageResultExecution timeMemory
375187dimashiiSjeckanje (COCI21_sjeckanje)C++17
15 / 110
2078 ms548 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; const int mxN = 1e6 + 5, mod = 1e9 + 7; const ll inf = 1e18; ll n, q, a[mxN]; ll d[mxN]; int main() { ios :: sync_with_stdio(false), cin.tie(nullptr); cin >> n >> q; for (int i = 1; i <= n; ++i) cin >> a[i]; while (q--) { int l, r, x; cin >> l >> r >> x; for (int i = l; i <= r; ++i) a[i] += x; for (int i = 1; i <= n; ++i) d[i] = -inf; for (int i = 1; i <= n; ++i) { ll mn = inf, mx = -inf; for (int j = i; j > 0; j--) { mn = min(mn, a[j]); mx = max(mx, a[j]); d[i] = max(d[i], d[j - 1] + mx - mn); } } cout << d[n] << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...