Submission #950260

#TimeUsernameProblemLanguageResultExecution timeMemory
950260vjudge1Sjeckanje (COCI21_sjeckanje)C++17
0 / 110
1 ms344 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define ff first #define ss second #define all(a) a.begin(), a.end() #define int long long int f(vector<int> &a){ int n = a.size(); vector<int> dp(n); dp[0] = 0, dp[1] = abs(a[0] - a[1]); for(int i = 2;i < n; i++){ dp[i] = max(dp[i-1], dp[i-2] + abs(a[i] - a[i-1])); if(i-3 >= 0) dp[i] = max(dp[i], dp[i-3] + max({a[i], a[i-1], a[i-2]}) - min({a[i], a[i-1], a[i-2]})); } return *max_element(all(dp)); } signed main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, q; cin >> n >> q; vector<int> a(n); for(auto &e : a) cin >> e; while(q--){ int l, r, x; cin >> l >> r >> x; l--, r--; vector<int> v; for(int i = 0;i < n; i++){ if(l <= i && r >= i) a[i]+= x; if(v.size() >= 2 && a[i] == v[v.size()-1] && a[i] == v[v.size()-2]){ continue; } v.push_back(a[i]); } cout << f(v) << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...