Submission #1108584

#TimeUsernameProblemLanguageResultExecution timeMemory
1108584huantranSjeckanje (COCI21_sjeckanje)C++17
15 / 110
2057 ms2552 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long int; const int maxn = 2e5 + 5; const int oo = 1e9 + 7; const ll inf = 1e18; int n, q; ll a[maxn], st[4*maxn], dp[maxn]; void sub1() { // O(n^2 * q) 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; dp[0] = 0; for (int i = 1; i <= n; i++) { dp[i] = 0; ll mx = a[i]; ll mn = a[i]; for (int j = i; j >= 1; j--) { mx = max(mx, a[j]); mn = min(mn, a[j]); dp[i] = max(dp[i], mx - mn + dp[j - 1]); } } cout << dp[n] << '\n'; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); sub1(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...