제출 #1135620

#제출 시각아이디문제언어결과실행 시간메모리
1135620DangKhoizzzzSjeckanje (COCI21_sjeckanje)C++20
15 / 110
10 ms328 KiB
#include <bits/stdc++.h> #define int long long #define fi first #define se second #define pii pair <int , int> #define ar3 array <int , 3> using namespace std; const int INF = 1e9 + 7; const int maxn = 500 + 5; const int maxk = 2507; int n , q , a[maxn] , dp[maxn]; void solve() { cin >> n >> q; for(int i = 1; i <= n; i++) cin >> a[i]; dp[0] = 0; while(q--) { int l , r , x; cin >> l >> r >> x; for(int i = l; i <= r; i++) a[i] += x; for(int i = 1; i <= n; i++) { int mx = -INF*INF; int mn = INF*INF; dp[i] = 0; for(int j = i; j >= 1; j--) { mx = max(a[j] , mx); mn = min(a[j] , mn); dp[i] = max(dp[j-1] + mx - mn , dp[i]); } } //for(int i = 1; i <= n; i++) cout << a[i] << ' '; cout << '\n'; //for(int i = 1; i <= n; i++) cout << dp[i] << ' '; cout << '\n'; cout << dp[n] << '\n'; } } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...