Submission #1075632

#TimeUsernameProblemLanguageResultExecution timeMemory
1075632tradzHolding (COCI20_holding)C++14
55 / 110
108 ms204584 KiB
#include <bits/stdc++.h> #define For(i,a,b) for(int i = a; i <= b; i++) #define Ford(i,a,b) for(int i = a; i >= b; i--) #define ll long long #define ii pair<int,int> #define fi first #define se second #define all(v) v.begin(),v.end() #define RRH(v) v.resize(unique(all(v)) - v.begin()) using namespace std; const int N = 1e6+7; const int M = 1e9+7; const ll oo = 3e18; int n, l, r, k; int a[N]; int dpL[102][102][2507]; int dpR[102][102][2507]; int main() { ios::sync_with_stdio(0); cin.tie(0); #define TASK "" if (fopen (".inp", "r")) { freopen (".inp", "r", stdin); freopen (".out", "w", stdout); } if(fopen(TASK".inp", "r")) { freopen(TASK".inp", "r", stdin); freopen(TASK".out", "w", stdout); } cin >> n >> l >> r >> k; memset(dpL, 0, sizeof dpL); memset(dpR, 0, sizeof dpR); For (i, 1, n) cin >> a[i]; k = min(k, n * n / 4); int sum = 0; for (int i = l; i <= r; i++) sum += a[i]; for (int i = 1; i < l; i++) { for (int j = l; j <= r; j++) { for (int h = 0; h <= k; h++) { dpL[i][j][h] = max(dpL[i - 1][j][h], dpL[i][j - 1][h]); if (h >= (j - i)) dpL[i][j][h] = max(dpL[i][j][h], dpL[i - 1][j - 1][h - j + i] + a[j] - a[i]); } } } for (int i = n; i > r; i--) { for (int j = r; j >= l; j--) { for (int h = 0; h <= k; h++) { dpR[j][i][h] = max(dpR[j + 1][i][h], dpR[j][i + 1][h]); if (h >= (i - j)) dpR[j][i][h] = max(dpR[j][i][h], dpR[j + 1][i + 1][k - i + j] + a[j] - a[i]); } } } int ans = 0; ans = max(dpL[l - 1][r][k], dpR[l][r + 1][k]); for (int i = l; i <= r; i++) { for (int h = 0; h <= k; h++) { ans = max(ans, dpL[l - 1][i][h] + dpR[i + 1][r + 1][k - h]); } } cout << sum - ans << '\n'; return 0; }

Compilation message (stderr)

holding.cpp: In function 'int main()':
holding.cpp:28:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |         freopen (".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~
holding.cpp:29:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |         freopen (".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
holding.cpp:32:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |         freopen(TASK".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
holding.cpp:33:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |         freopen(TASK".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...