Submission #1011686

# Submission time Handle Problem Language Result Execution time Memory
1011686 2024-07-01T05:35:07 Z pcc Sjeckanje (COCI21_sjeckanje) C++17
0 / 110
0 ms 348 KB
#include <bits/stdc++.h>
using namespace std;


#define ll long long
#define pll pair<ll,ll>
#define fs first
#define sc second
#define pii pair<int,int>

const int mxn = 3030;
const ll inf = 1e18;
int arr[mxn];
ll dp[mxn];
int N,Q;

ll getans(){
	pll mx = pll(-inf,-inf);
	dp[1] = 0;
	mx.fs = -arr[1];
	mx.sc = arr[1];
	for(int i = 1;i<=N;i++){
		dp[i] = max(arr[i]+mx.fs,-arr[i]+mx.sc);
		mx.fs = max(mx.fs,dp[i]-arr[i+1]);
		mx.sc = max(mx.sc,dp[i]+arr[i+1]);
	}
	return dp[N];
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>N>>Q;
	for(int i = 1;i<=N;i++)cin>>arr[i];
	while(Q--){
		int l,r,v;
		cin>>l>>r>>v;
		for(int i = l;i<=r;i++)arr[i] += v;
		cout<<getans()<<'\n';
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Halted 0 ms 0 KB -