#include <iostream>
#define MAXN 100005
#define intt long long
using namespace std ;
intt n , k , a[MAXN] , dp[MAXN][105] , q[MAXN][105] ;
int main () {
cin >> n >> k ;
for ( int i = 1 ; i <= n ; i ++ ) cin >> a[i] ;
for ( int i = 1 ; i <= n ; i ++ )
for ( int v = 1 ; v <= k ; v ++ ) dp[i][v] = 343334344 ;
dp[1][1] = a[1] ;
for ( intt i = 2 ; i <= n ; i ++ ) {
dp[i][1] = max ( dp[i - 1][1] , a[i] ) ;
for ( int v = 2 ; v <= min ( i , k ) ; v ++ ) {
intt mx = 0 ;
dp[i][v] = dp[i - 1][v - 1] + a[i] ;
for ( int j = i - 1 ; j >= 2 ; j -- ) {
if ( j < v - 1 ) break ;
mx = max ( mx , a[j + 1] ) ;
if ( dp[i][v] > dp[j][v - 1] + mx ) dp[i][v] = dp[j][v - 1] + mx ;
}
}
}
cout << dp[n][k] << endl ;
return 0 ;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
166572 KB |
Output is correct |
2 |
Correct |
0 ms |
166572 KB |
Output is correct |
3 |
Correct |
0 ms |
166572 KB |
Output is correct |
4 |
Correct |
0 ms |
166572 KB |
Output is correct |
5 |
Correct |
0 ms |
166572 KB |
Output is correct |
6 |
Correct |
0 ms |
166572 KB |
Output is correct |
7 |
Correct |
0 ms |
166572 KB |
Output is correct |
8 |
Correct |
0 ms |
166572 KB |
Output is correct |
9 |
Correct |
0 ms |
166572 KB |
Output is correct |
10 |
Correct |
0 ms |
166572 KB |
Output is correct |
11 |
Correct |
0 ms |
166572 KB |
Output is correct |
12 |
Correct |
0 ms |
166572 KB |
Output is correct |
13 |
Correct |
0 ms |
166572 KB |
Output is correct |
14 |
Correct |
0 ms |
166572 KB |
Output is correct |
15 |
Correct |
0 ms |
166572 KB |
Output is correct |
16 |
Incorrect |
0 ms |
166572 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Halted |
0 ms |
0 KB |
- |