Submission #1295983

#TimeUsernameProblemLanguageResultExecution timeMemory
1295983qweqerSjeckanje (COCI21_sjeckanje)C++20
0 / 110
0 ms332 KiB
#include <bits/stdc++.h>
#define FOR(i, beg, ed, etr) for(ll i = beg;i <= ed;i += etr)
#define FORN(i, beg, ed, etr) for(ll i = beg;i >= ed;i -= etr)
#define all(x) x.begin(), x.end()
#define F first
#define pb push_back
#define S second
#define con continue
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
typedef pair<ll,ll> pll;
typedef double db;
typedef long double ld;

const ll inf = 1e9;
const ll INF = 1e18;
const ll N = 3000 + 5;
const ll MOD = 1e9 + 7;

ll a[N],dp[N],mx[N],mn[N];
ll t[4 * N], tp[N];
void solve(){
    ll n,q;cin >> n >> q;
    FOR(i, 1, n, 1){
        cin >> a[i];
    }
    while(q--){
        ll l,r,x;cin >> l >> r >> x;
        FOR(i, l, r, 1){
            a[i] += x;
        }
        FOR(i, 1, n, 1){
        }
        FOR(i, 1, n, 1){
            dp[i] = dp[i-1];
            if(i > 1){
                if(a[i] > a[i-1] && tp[i-1] >= 0){
                    dp[i] = max(dp[i],dp[i-1] + (a[i] - mn[i-1]));
                    mn[i] = mn[i-1];
                    mx[i] = a[i];
                    tp[i] = 1;
                }
                else if(a[i] < a[i-1] && tp[i-1] <= 0){
                    dp[i] = max(dp[i],dp[i-1] + (mx[i-1] - a[i]));
                    mx[i] = mx[i-1];
                    mn[i] = a[i];
                    tp[i] = -1;
                }
                else {
                    mn[i] = a[i];
                    mx[i] = a[i];
                    tp[i] = 0;
                }
            }
            else{
                mn[i] = a[i];
                mx[i] = a[i];
                tp[i] = 0;
            }
        }
        cout << dp[n] << '\n';
    }
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
//    freopen("cardgame.in","r",stdin);
//    freopen("cardgame.out","w",stdout);
    ll abd = 1;
//    cin >> abd;

    FOR(i, 1, abd, 1){
        solve();
    }
}

Compilation message (stderr)

Main.cpp:65:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   65 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...