#include<bits/stdc++.h>
using namespace std;
const int MAXN=100005,MAXK=105;
long long dp[MAXN][MAXK];
int a[MAXN];
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int N,K;
cin >> N >> K;
for(int i=1;i<=N;i++)cin >> a[i];
for(int i=1;i<=N;i++){
for(int j=1;j<=min(i,K);j++){
dp[i][j]=1e18;
int maxi=a[i];
for(int k=i-1;k>=0;k--){
if(k>=j-1)dp[i][j]=min(dp[i][j],dp[k][j-1]+maxi);
maxi=max(maxi,a[k]);
}
}
}
cout << dp[N][K] << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |