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>
#define fu(i, a, b) for(int i = (a); i <= (b); i++)
#define fd(i, a, b) for(int i = (a); i >= (b); i--)
#define ll long long
#define pii pair<int, int>
#define mp(x, y) make_pair(x, y)
#define bit(mask, x) ((mask >> x) & 1)
using namespace std;
const int N = (int)2e5 + 5;
const int LOG = 19;
const ll INF = (ll)1e18 + 5;
const int MOD = 111539786;
int n, lim;
int a[N];
ll f[105][105];
void read()
{
cin >> n >> lim;
fu(i, 1, n) cin >> a[i];
int mx = 0;
fu(i, 0, n) fu(j, 0, lim) f[i][j] = INF;
f[0][0] = 0;
fu(i, 1, n)
{
mx = max(mx, a[i]);
int amax = 0;
f[i][1] = mx;
fd(j, i, 1)
{
amax = max(amax, a[j]);
fu(k, 1, min(i, lim)) {
if(f[j - 1][k - 1] != INF) f[i][k] = min(f[i][k], f[j - 1][k - 1] + amax);
}
}
}
cout << f[n][lim];
}
int main()
{
// freopen("thaydongA.inp","r",stdin);
// freopen("thaydongA.out","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(0);
read();
}
# | 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... |