Submission #1278863

#TimeUsernameProblemLanguageResultExecution timeMemory
1278863Robert_juniorSjeckanje (COCI21_sjeckanje)C++20
0 / 110
5 ms332 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back  
#define all(x) x.begin(), x.end()
#define ins insert
#define F first
#define S second
#define ld long double
const int N = 1e5 + 7, mod = 1e9 + 7;
int dp[N][2], a[N];
void solve(){
    int n, 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;
        }
        for(int i = 1; i <= n; i++){
            dp[i][0] = dp[i][1] = 0;
        }
        int ans = 0;
        for(int i = 1; i <= n; i++){
            for(int j = i; j <= n; j++){
                dp[j][1] = max(dp[j][1], dp[i - 1][0] + (a[j] - a[i]));
                dp[j][0] = max(dp[j][0], dp[i - 1][1] + (a[i] - a[j]));
            }
            dp[i][1] = max(dp[i][1], dp[i - 1][1]);
            dp[i][0] = max(dp[i][0], dp[i - 1][0]); 
        }
        cout<<max(dp[n][1], dp[n][0])<<'\n';
    }
}
signed main(){
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
    //freopen("area.in", "r", stdin);
    //freopen("area.out", "w", stdout);
    int t = 1;
    //cin>>t;
    while(t--){
        solve();
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...