Submission #545060

# Submission time Handle Problem Language Result Execution time Memory
545060 2022-04-03T13:22:35 Z MohamedFaresNebili Sjeckanje (COCI21_sjeckanje) C++14
15 / 110
2000 ms 668 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[3001], dp[3001];
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 9 ms 340 KB Output is correct
2 Correct 8 ms 340 KB Output is correct
3 Correct 9 ms 372 KB Output is correct
4 Correct 8 ms 340 KB Output is correct
5 Correct 8 ms 340 KB Output is correct
6 Correct 9 ms 368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 340 KB Output is correct
2 Correct 8 ms 340 KB Output is correct
3 Correct 9 ms 372 KB Output is correct
4 Correct 8 ms 340 KB Output is correct
5 Correct 8 ms 340 KB Output is correct
6 Correct 9 ms 368 KB Output is correct
7 Execution timed out 2084 ms 668 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 340 KB Output is correct
2 Correct 8 ms 340 KB Output is correct
3 Correct 9 ms 372 KB Output is correct
4 Correct 8 ms 340 KB Output is correct
5 Correct 8 ms 340 KB Output is correct
6 Correct 9 ms 368 KB Output is correct
7 Execution timed out 2084 ms 668 KB Time limit exceeded
8 Halted 0 ms 0 KB -