제출 #379309

#제출 시각아이디문제언어결과실행 시간메모리
379309limabeansSjeckanje (COCI21_sjeckanje)C++17
15 / 110
2088 ms568 KiB
#include <bits/stdc++.h> using namespace std; template<typename T> void out(T x) { cout << x << endl; exit(0); } #define watch(x) cout << (#x) << " is " << (x) << endl using ll = long long; const int maxn = 1e6 + 5; int n,q; ll a[maxn]; ll solve() { vector<ll> dp(n,0); for (int i=0; i<n; i++) { ll lo = a[i]; ll hi = a[i]; for (int j=i; j>=0; j--) { ll rest = j>0 ? dp[j-1] : 0; lo = min(lo, a[j]); hi = max(hi, a[j]); dp[i] = max(dp[i], hi-lo+rest); } } return dp[n-1]; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>n>>q; for (int i=0; i<n; i++) { cin>>a[i]; } while (q--) { int l,r,dx; cin>>l>>r>>dx; --l; --r; for (int i=l; i<=r; i++) { a[i] += dx; } cout<<solve()<<"\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...