Submission #950262

# Submission time Handle Problem Language Result Execution time Memory
950262 2024-03-20T07:27:37 Z vjudge1 Sjeckanje (COCI21_sjeckanje) C++17
15 / 110
2000 ms 604 KB
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define int long long



int f(vector<int> &a){
    int n = a.size();
    vector<int> dp(n);
    dp[0] = 0, dp[1] = abs(a[0] - a[1]);
    for(int i = 2;i < n; i++){
        int mn = a[i], mx = a[i];
        for(int j = i-1; j >= 0; j--){
            mn = min(mn, a[j]);
            mx = max(mx, a[j]);
            dp[i] = max((j > 0 ? dp[j-1] : 0) + mx - mn, dp[i]);
        }
    }
    return *max_element(all(dp));
}


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n, q; cin >> n >> q;
    vector<int> a(n);
    for(auto &e : a) cin >> e;
    while(q--){
        int l, r, x; cin >> l >> r >> x;
        l--, r--;
        vector<int> v;
        for(int i = 0;i < n; i++){
            if(l <= i && r >= i) a[i]+= x;
            if(v.size() >= 2 && a[i] == v[v.size()-1] && a[i] == v[v.size()-2]){
                continue;
            }
            v.push_back(a[i]);
        }
       
        cout << f(v) << '\n';
    }
    return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 6 ms 348 KB Output is correct
3 Correct 6 ms 460 KB Output is correct
4 Correct 8 ms 344 KB Output is correct
5 Correct 6 ms 348 KB Output is correct
6 Correct 8 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 6 ms 348 KB Output is correct
3 Correct 6 ms 460 KB Output is correct
4 Correct 8 ms 344 KB Output is correct
5 Correct 6 ms 348 KB Output is correct
6 Correct 8 ms 348 KB Output is correct
7 Execution timed out 2072 ms 604 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 6 ms 348 KB Output is correct
3 Correct 6 ms 460 KB Output is correct
4 Correct 8 ms 344 KB Output is correct
5 Correct 6 ms 348 KB Output is correct
6 Correct 8 ms 348 KB Output is correct
7 Execution timed out 2072 ms 604 KB Time limit exceeded
8 Halted 0 ms 0 KB -