제출 #291101

#제출 시각아이디문제언어결과실행 시간메모리
291101penguinhackerHolding (COCI20_holding)C++17
110 / 110
161 ms2936 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ar array const int INF=1e9; int n, l, r, k, a[100]; //int dp[10000][100]; //minimum cost given used i operations and have selected from first j elements //what do we need to know //we need cost used, used first [] elements, and have chosen first [] elements //maybe only maintain 2 things, such as cost, and chosen first [] elements void debug(vector<vector<int>> &v) { for (auto& x: v) { for (int i: x) cout << i << " "; cout << "\n"; } cout << "\n"; } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> l >> r >> k, --l, --r; for (int i=0; i<n; ++i) cin >> a[i]; //memset(dp, 0x3f, sizeof(dp)); vector<vector<int>> dp(k+1, vector<int>(r-l+2, INF)); dp[0][0]=0; for (int pos=0; pos<n; ++pos) { //vector<vector<int>> dpl=dp; for (int i=min(r-l+1, pos+1); i>0; --i) { int cost=abs(l+i-1-pos); for (int j=k; j>=cost; --j) dp[j][i]=min(dp[j][i], dp[j-cost][i-1]+a[pos]); //for (int j=cost; j<=k; ++j) dp[j][i]=min(dp[j][i], dpl[j-cost][i-1]+a[pos]); } //debug(dp); } int ans=INF; for (int i=0; i<=k; ++i) ans=min(ans, dp[i][r-l+1]); cout << ans << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...