Submission #869857

#TimeUsernameProblemLanguageResultExecution timeMemory
869857prohackerHolding (COCI20_holding)C++14
110 / 110
28 ms30196 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double using namespace std; const int N = 105; const int INF = INT_MAX; const int mod = 1e9+7; int n,m,l,r; int a[N]; int ans,dp[N][N][3005],f[N][N][3005],sum; signed main() { if (fopen("DEBT.inp", "r")) { freopen("DEBT.inp", "r", stdin); freopen("DEBT.out", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> l >> r >> m; m = min(m,3000); for(int i = 1 ; i <= n ; i++) { cin >> a[i]; if(l <= i and i <= r) { sum += a[i]; } } for(int i = 1 ; i < l ; i++) { for(int j = l ; j <= r ; j++) { for(int k = 0 ; k <= m ; k++) { dp[i][j][k] = max(dp[i][j][k],dp[i-1][j][k]); dp[i][j][k] = max(dp[i][j][k],dp[i][j-1][k]); if(k >= j-i) { dp[i][j][k] = max(dp[i][j][k],dp[i-1][j-1][k-j+i]+a[j]-a[i]); } } } } for(int i = n ; i > r ; i--) { for(int j = r ; j >= l ; j--) { for(int k = 0 ; k <= m ; k++) { f[j][i][k] = max(f[j][i][k],f[j][i+1][k]); f[j][i][k] = max(f[j][i][k],f[j+1][i][k]); if(k >= i-j) { f[j][i][k] = max(f[j][i][k],f[j+1][i+1][k+j-i]+a[j]-a[i]); } } } } int ans = 0; ans = max(dp[l-1][r][m],f[l][r+1][m]); for(int i = l ; i < r ; i++) { for(int k = 0 ; k <= m ; k++) { ans = max(ans,dp[l-1][i][k]+f[i+1][r+1][m-k]); } } cout << sum-ans; return 0; }

Compilation message (stderr)

holding.cpp: In function 'int main()':
holding.cpp:18:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         freopen("DEBT.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
holding.cpp:19:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         freopen("DEBT.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...