Submission #330404

#TimeUsernameProblemLanguageResultExecution timeMemory
330404534351Holding (COCI20_holding)C++17
110 / 110
167 ms4900 KiB
#include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> using namespace std; // using namespace __gnu_pbds; // template<class T> // using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template<class T, class U> void ckmin(T &a, U b) { if (a > b) a = b; } template<class T, class U> void ckmax(T &a, U b) { if (a < b) a = b; } #define MP make_pair #define PB push_back #define LB lower_bound #define UB upper_bound #define fi first #define se second #define SZ(x) ((int) (x).size()) #define ALL(x) (x).begin(), (x).end() #define FOR(i, a, b) for (auto i = (a); i < (b); i++) #define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--) typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vpi; typedef vector<pll> vpl; const int INF = 1e9 + 7; const int MAXN = 113; int N, L, R, K; int arr[MAXN]; int dp[2][MAXN][MAXN * MAXN]; int ans; int32_t main() { cout << fixed << setprecision(12); cerr << fixed << setprecision(4); ios_base::sync_with_stdio(false); cin.tie(0); cin >> N >> L >> R >> K; L--; R--; FOR(i, 0, N) { cin >> arr[i]; } FOR(j, 0, R - L + 2) { FOR(k, 0, K + 1) { dp[1][j][k] = INF; } } dp[1][0][0] = 0; FOR(i, 0, N) //dp[pos][# numbers selected][# moves] { FOR(j, 0, R - L + 2) { FOR(k, 0, K + 1) { dp[0][j][k] = dp[1][j][k]; dp[1][j][k] = INF; } } FOR(j, 0, R - L + 2) { FOR(k, 0, K + 1) { //select another number. ckmin(dp[1][j + 1][k + abs(i - (L + j))], dp[0][j][k] + arr[i]); //don't select another number. ckmin(dp[1][j][k], dp[0][j][k]); } } } ans = INF; FOR(k, 0, K + 1) { ckmin(ans, dp[1][R - L + 1][k]); } 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...