Submission #386326

#TimeUsernameProblemLanguageResultExecution timeMemory
386326phathnvSjeckanje (COCI21_sjeckanje)C++11
55 / 110
48 ms748 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 3007; int n, q, a[N]; ll b[N], dp[N][2]; int getSign(ll x){ if (x < 0) return -1; else if (x == 0) return 0; else return 1; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> q; if (max(n, q) > 3000) return 0; for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = 1; i < n; i++) b[i] = a[i + 1] - a[i]; while (q--){ int l, r, x; cin >> l >> r >> x; if (l > 1) b[l - 1] += x; if (r < n) b[r] -= x; // cerr << "b: "; // for(int i = 1; i < n; i++) // cerr << b[i] << ' '; // cerr << endl; dp[0][0] = dp[0][1] = 0; for(int i = 1; i < n; i++){ dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]); dp[i][1] = dp[i - 1][0] + abs(b[i]); if (getSign(b[i - 1]) * getSign(b[i]) != -1) dp[i][1] = max(dp[i][1], dp[i - 1][1] + abs(b[i])); } cout << max(dp[n - 1][0], dp[n - 1][1]) << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...