Submission #522839

# Submission time Handle Problem Language Result Execution time Memory
522839 2022-02-06T01:33:12 Z julian33 Sjeckanje (COCI21_sjeckanje) C++14
15 / 110
2000 ms 384 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int mxN=2e5+5;

ll a[mxN],dp[mxN],go[mxN];

int main(){
    cin.sync_with_stdio(0); cin.tie(0);

    #ifdef LOCAL
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif

    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++){
            ll lo=1e18; ll hi=-1e18;
            dp[i]=0; go[i]=0;
            for(int j=i-1;j>=0;j--){
                lo=min(lo,a[j+1]);
                hi=max(hi,a[j+1]);
                if(dp[i]<=hi-lo+dp[j]){
                    dp[i]=hi-lo+dp[j];
                    go[i]=j;
                }
            }
            assert(go[i]>=go[i-1]);
        }
        cout<<dp[n]<<"\n";
    }
}   
# Verdict Execution time Memory Grader output
1 Correct 7 ms 332 KB Output is correct
2 Correct 6 ms 340 KB Output is correct
3 Correct 7 ms 332 KB Output is correct
4 Correct 7 ms 340 KB Output is correct
5 Correct 11 ms 344 KB Output is correct
6 Correct 10 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 332 KB Output is correct
2 Correct 6 ms 340 KB Output is correct
3 Correct 7 ms 332 KB Output is correct
4 Correct 7 ms 340 KB Output is correct
5 Correct 11 ms 344 KB Output is correct
6 Correct 10 ms 340 KB Output is correct
7 Execution timed out 2084 ms 384 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 332 KB Output is correct
2 Correct 6 ms 340 KB Output is correct
3 Correct 7 ms 332 KB Output is correct
4 Correct 7 ms 340 KB Output is correct
5 Correct 11 ms 344 KB Output is correct
6 Correct 10 ms 340 KB Output is correct
7 Execution timed out 2084 ms 384 KB Time limit exceeded
8 Halted 0 ms 0 KB -