# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1242851 | hainam2k9 | Holding (COCI20_holding) | C++20 | 156 ms | 12508 KiB |
#include <bits/stdc++.h>
#define tt cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0)
#define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define db long double
#define sz(a) ((int)(a).size())
#define pb emplace_back
#define pf emplace_front
#define pob pop_back
#define pof pop_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define ins emplace
#define mp make_pair
using namespace std;
const int MOD = 1e9+7, MAXN = 1e5+5, offset = 100;
const string NAME = "";
int n,l,r,k,a[105],dp[205][10005],nxtdp[205][10005],rs=1e9;
inline void chmin(int& a, int b){
a=min(a,b);
}
int main()
{
tt;
if(fopen((NAME + ".INP").c_str(), "r")) fo;
cin >> n >> l >> r >> k;
for(int i = 1; i<=n; ++i)
cin >> a[i];
int sz=r-l+1;
memset(nxtdp,0x3f,sizeof(nxtdp));
nxtdp[offset][0]=accumulate(a+l,a+r+1,0);
for(int i = 0; i<n; ++i){
for(int j = -sz; j<=sz; ++j)
for(int cost = 0; cost<=k; ++cost)
dp[j+offset][cost]=nxtdp[j+offset][cost], nxtdp[j+offset][cost]=1e9;
for(int j = -sz; j<=sz; ++j)
for(int cost = 0; cost<=k; ++cost){
if(dp[j+offset][cost]>=1e9) continue;
int newcost=cost+abs(j);
if(newcost>k) continue;
chmin(nxtdp[j+offset][newcost],dp[j+offset][cost]);
if(j<sz&&(i+1<l||i+1>r)) chmin(nxtdp[j+1+offset][newcost],dp[j+offset][cost]+a[i+1]);
if(j>-sz&&i+1>=l&&i+1<=r) chmin(nxtdp[j-1+offset][newcost],dp[j+offset][cost]-a[i+1]);
}
}
for(int cost = 0; cost<=k; ++cost)
rs=min(rs,nxtdp[offset][cost]);
cout << rs;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |