Submission #545060

#TimeUsernameProblemLanguageResultExecution timeMemory
545060MohamedFaresNebiliSjeckanje (COCI21_sjeckanje)C++14
15 / 110
2084 ms668 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...