이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
#define int long long
const int maxn = 1e5 + 69;
const int maxk = 110;
const int lg = 17;
const int inf = 1e18;
int a[maxn], n, k, dp[maxn][maxk], st[maxn][lg];
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tt = 1;
//cin >> tt;
while(tt--) {
cin >> n >> k;
for (int i = 1;i <= n;i++)
cin >> a[i];
for (int i = 1;i <= n;i++)
st[i][0] = a[i];
for (int i = 0;i <= n;i++) {
for (int j = 0;j <= k;j++)
dp[i][j] = inf;
}
dp[0][0] = 0;
for (int j = 1;j < lg;j++)
for (int i = 1;i + (1 << j) <= n + 1;i++)
st[i][j] = max(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);
for (int i = 1;i <= n;i++) {
for (int j = 1;j <= k;j++) {
for (int x = i - 1;x >= 0;x--) {
int q = log2(i - x);
int mx = max(st[x + 1][q], st[i - (1 << q) + 1][q]);
dp[i][j] = min(dp[i][j], mx + dp[x][j - 1]);
}
}
}
cout << dp[n][k];
}
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... |