This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl
const int maxn = 102;
const int inf = 2e9;
int dp[2][maxn][maxn*maxn]; //dp[i][j][k]: first i elems, jth elem in range, k moves: min sum
int n,l,r,ops;
int a[maxn];
void upd(int &x, int y) {
x = min(x, y);
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin>>n>>l>>r>>ops;
--l; --r;
for (int i=0; i<n; i++) {
cin>>a[i];
}
int len = r-l+1;
for (int i=0; i<=len; i++) {
for (int k=0; k<=ops; k++) {
dp[1][i][k] = inf;
}
}
dp[1][0][0] = 0;
for (int i=0; i<n; i++) {
for (int j=0; j<=len; j++) {
for (int k=0; k<=ops; k++) {
dp[0][j][k] = dp[1][j][k];
dp[1][j][k] = inf;
}
}
for (int j=0; j<=len; j++) {
for (int k=0; k<=ops; k++) {
// move ith elem
int mvs = abs(i-(l+j));
if (k+mvs<=ops) {
upd(dp[1][j+1][k+mvs], a[i]+dp[0][j][k]);
}
// do nothing
upd(dp[1][j][k], dp[0][j][k]);
}
}
}
int res = inf;
for (int k=0; k<=ops; k++) {
upd(res, dp[1][len][k]);
}
cout<<res<<endl;
return 0;
}
# | 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... |