Submission #469817

# Submission time Handle Problem Language Result Execution time Memory
469817 2021-09-01T19:51:02 Z MohamedFaresNebili Sjeckanje (COCI21_sjeckanje) C++14
15 / 110
2000 ms 2124 KB
#include <bits/stdc++.h>

using namespace std;

using ll  = long long;
using ld  = long double;

#define pb push_back
#define pp pop_back
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define all(x) (x).begin() , (x).end()

const ll MOD = 998244353;
const long double EPS = 0.000000001;

ll n, q, arr[200005], dp[200005];
ll solve(ll i) {
    if(dp[i]!=-1) return dp[i];
    ll mn=arr[i], mx=arr[i], best=0;
    for(ll l=i;l<=n;l++) {
        mx=max(mx, arr[l]); mn=min(mn, arr[l]);
        best=max(best, mx-mn+solve(l+1));
    }
    return dp[i]=best;
}

int32_t main()
{
    ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
    cin>>n>>q;
    for(ll l=1;l<=n;l++) cin>>arr[l];
    while(q--) {
        ll a, b, val; cin>>a>>b>>val;
        for(int l=a;l<=b;l++) arr[l]+=val;
        memset(dp, -1, sizeof dp);
        cout<<solve(1)<<'\n';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 21 ms 1904 KB Output is correct
2 Correct 20 ms 1868 KB Output is correct
3 Correct 21 ms 1896 KB Output is correct
4 Correct 22 ms 1896 KB Output is correct
5 Correct 21 ms 1868 KB Output is correct
6 Correct 21 ms 1900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 1904 KB Output is correct
2 Correct 20 ms 1868 KB Output is correct
3 Correct 21 ms 1896 KB Output is correct
4 Correct 22 ms 1896 KB Output is correct
5 Correct 21 ms 1868 KB Output is correct
6 Correct 21 ms 1900 KB Output is correct
7 Execution timed out 2086 ms 2124 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 21 ms 1904 KB Output is correct
2 Correct 20 ms 1868 KB Output is correct
3 Correct 21 ms 1896 KB Output is correct
4 Correct 22 ms 1896 KB Output is correct
5 Correct 21 ms 1868 KB Output is correct
6 Correct 21 ms 1900 KB Output is correct
7 Execution timed out 2086 ms 2124 KB Time limit exceeded
8 Halted 0 ms 0 KB -