Submission #694196

#TimeUsernameProblemLanguageResultExecution timeMemory
694196TrungNotChungSjeckanje (COCI21_sjeckanje)C++11
55 / 110
91 ms724 KiB
//TrungNotChung #include <bits/stdc++.h> #define pii pair<int , int> #define fi first #define se second #define BIT(x,i) (1&((x)>>(i))) #define MASK(x) (1LL<<(x)) #define CNT(x) __builtin_popcountll(x) #define task "tnc" using namespace std; const int N = 3030; const long long INF = (long long)1e18; void maximize(long long &x, const long long &y) { x = max(x, y); } int n, q; long long a[N], dp[N][2][2]; void solve() { 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; memset(dp, -0x3f, sizeof(dp)); dp[0][0][0] = 0; for(int i=0; i<n; ++i) { for(int j=0; j<=1; ++j) { for(int k=0; k<=1; ++k) { maximize(dp[i+1][j][k], dp[i][j][k]); if(k == 0 || j == 0) maximize(dp[i+1][1][1^k], dp[i][j][k] + a[i+1]); if(k == 0 || j == 1) maximize(dp[i+1][0][1^k], dp[i][j][k] - a[i+1]); } } } long long res = -INF; for(int i=0; i<=1; ++i) maximize(res, dp[n][i][0]); cout << res << '\n'; } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); solve(); //cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...