Submission #486918

#TimeUsernameProblemLanguageResultExecution timeMemory
486918AkiYuuHolding (COCI20_holding)C++17
110 / 110
20 ms26016 KiB
#include <bits/stdc++.h> #define task "GROUP" #define ll long long #define ld long double #define pb(u) emplace_back(u) #define ffw(i,a,b) for (ll i = a; i <= b; i++) #define fbw(i,b,a) for (ll i = b; i >= a; i--) #define adj(v,adj,u) for (auto v : adj[u]) #define rep(i,a) for (auto i : a) #define reset(a) memset(a, 0, sizeof(a)) #define sz(a) a.size() #define all(a) a.begin(),a.end() using namespace std; inline namespace FastIO { const int BSZ = 1<<15; char ibuf[BSZ]; int ipos, ilen; char nc() { // if (ipos == ilen) { ipos = 0; ilen = fread(ibuf,1,BSZ,stdin); if (!ilen) return EOF; } return ibuf[ipos++]; } void readstr(string& x) { char ch; while (isspace(ch = nc())); do { x += ch; } while (!isspace(ch = nc()) && ch != EOF); } template<class T> void readnum(T& x){ char ch; int sgn = 1; while (!isdigit(ch = nc())) if (ch == '-') sgn *= -1; x = ch-'0'; while (isdigit(ch = nc())) x = x*10+(ch-'0'); x *= sgn; } } void fastio(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); // freopen(task".inp", "r", stdin); // freopen(task".out", "w", stdout); } const int mxn = 1e6 + 5; typedef pair<ll, ll> ii; ll a[1000]; ll n , L , R, k; ll tot = 0; int dpL[105][105][2600]; int dpR[105][105][2600]; void CredpL(){ ffw(i,L,R) fbw(j,L-1,1) ffw(c, 0, k){ int state1 = dpL[i-1][j][c]; int state2 = dpL[i][j+1][c]; int state3 = INT_MIN; if ( c >= i - j ) state3 = dpL[i-1][j+1][c - (i - j) ] + a[i] - a[j]; dpL[i][j][c] = max({state1, state2, state3}); } } void CredpR(){ fbw(i,R,L) ffw(j,R+1,n) ffw(c, 0, k){ int state1 = dpR[i+1][j][c]; int state2 = dpR[i][j-1][c]; int state3 = INT_MIN; if ( c >= j - i ) state3 = dpR[i+1][j-1][c - (j - i) ] + a[i] - a[j]; dpR[i][j][c] = max({state1, state2, state3}); } } void solve(){ cin >> n >> L >> R >> k; k = min(k, n*n/4 + 2); ffw(i,1,n) { cin >> a[i]; if ( i >= L && i <= R ) tot += a[i]; } int res = 0; CredpL(); CredpR(); ffw(i,L-1,R+1){ ffw(j,0,k){ res = max(res , dpL[i][1][j] + dpR[i+1][n][k-j] ); } } cout << tot - res; } int main(){ fastio(); solve(); } // _oo0oo_ // o8888888o // 88" . "88 // (| -_- |) // 0\ = /0 // ___/`---'\___ // .' \| |// '. // / \||| : |||// \ // / _||||| -:- |||||- \ // | | \\ - /// | | // | \_| ''\---/'' |_/ | // \ .-\__ '-' ___/-. / // ___'. .' /--.--\ `. .'___ // ."" '< `.___\_<|>_/___.' >' "". // | | : `- \`.;`\ _ /`;.`/ - ` : | | // \ \ `_. \_ __\ /__ _/ .-` / / // =====`-.____`.___ \_____/___.-`___.-'===== //

Compilation message (stderr)

holding.cpp:107:1: warning: multi-line comment [-Wcomment]
  107 | //                 / \|||  :  |||// \
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...