답안 #1069866

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1069866 2024-08-22T09:29:16 Z n1k Sjeckanje (COCI21_sjeckanje) C++17
15 / 110
2000 ms 604 KB
#include <bits/stdc++.h>

#if defined(LOCAL)
#include "debug.cpp"
#else
#define debug(x...) 0
#endif // LOCAL

using namespace std;

using ll = long long;

#define all(a) (a).begin(), (a).end()

void solve(){
	int n, q; cin >> n >> q;
	vector<ll> a(n);
	for(int i=0; i<n; i++) cin >> a[i];
	auto get = [&](vector<ll> a){
		vector<ll> dp(n+1);
		for(int i=0; i<n; i++){
			ll mn=a[i], mx = a[i];
			for(int j=i; j<n; j++){
				mn = min(mn, a[j]);
				mx = max(mx, a[j]);
				dp[j+1]=max(dp[j+1], dp[i]+mx - mn);
			}
		}
		return dp[n];
	};
	while(q--){
		ll l, r, add;
		cin>>l>>r>>add;
		l--, r--;
		for(int i=l; i<=r;i++) a[i]+=add;
		ll ans = get(a);
		cout<<ans<<endl;
	}
}

int main() {
	cin.tie(0)->sync_with_stdio(0);
	int t=1; //cin >> t;
	while(t--) solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 348 KB Output is correct
2 Correct 5 ms 452 KB Output is correct
3 Correct 5 ms 348 KB Output is correct
4 Correct 5 ms 344 KB Output is correct
5 Correct 5 ms 348 KB Output is correct
6 Correct 5 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 348 KB Output is correct
2 Correct 5 ms 452 KB Output is correct
3 Correct 5 ms 348 KB Output is correct
4 Correct 5 ms 344 KB Output is correct
5 Correct 5 ms 348 KB Output is correct
6 Correct 5 ms 348 KB Output is correct
7 Execution timed out 2062 ms 604 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 348 KB Output is correct
2 Correct 5 ms 452 KB Output is correct
3 Correct 5 ms 348 KB Output is correct
4 Correct 5 ms 344 KB Output is correct
5 Correct 5 ms 348 KB Output is correct
6 Correct 5 ms 348 KB Output is correct
7 Execution timed out 2062 ms 604 KB Time limit exceeded
8 Halted 0 ms 0 KB -