Submission #511161

#TimeUsernameProblemLanguageResultExecution timeMemory
511161danikoynovSjeckanje (COCI21_sjeckanje)C++14
0 / 110
2 ms204 KiB
/** ____ ____ ____ ____ ____ ____ ||l |||e |||i |||n |||a |||d || ||__|||__|||__|||__|||__|||__|| |/__\|/__\|/__\|/__\|/__\|/__\| **/ #include<bits/stdc++.h> #define endl '\n' using namespace std; typedef long long ll; void speed() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } const ll inf = 1e18; const int maxn = 3010; int n, q; ll a[maxn], dp[maxn][2]; void solve_dp() { dp[2][1] = abs(a[2] - a[1]); for (int i = 3; i <= n; i ++) { if ((a[i] >= a[i - 1] && a[i - 1] >= a[i - 2]) || (a[i] <= a[i - 1] && a[i - 1] <= a[i - 2])) { dp[i][1] = max(dp[i - 1][0], dp[i - 1][1]) + abs(a[i] - a[i - 1]); dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]); } else { dp[i][1] = dp[i - 1][0] + abs(a[i] - a[i - 1]); dp[i][0] = max(dp[i - 1][1], dp[i - 1][0]); } } } void solve() { cin >> n >> q; for (int i = 1; i <= n; i ++) cin >> a[i]; for (int i = 1; i <= q; i ++) { int l, r, x; cin >> l >> r >> x; for (int j = l; j <= r; j ++) a[j] += x; solve_dp(); cout << dp[n][1] << endl; } } int main() { solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...