#include <bits/stdc++.h>
#define maxn 100010
#define maxk 110
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define FORD(i,a,b) for(int i=a;i>=b;--i)
typedef long long ll;
using namespace std;
const char *fi="BLOCKS.INP";
const char *fo="BLOCKS.OUT";
int n,k,A[maxn],P[maxn];
ll F[maxn][maxk];
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// freopen(fi,"r",stdin);
// freopen(fo,"w",stdout);
cin>>n>>k;
FOR(i,1,n) cin>>A[i];
P[0]=0;
FOR(i,1,n) P[i]=max(P[i-1],A[i]);
FOR(i,1,n) F[i][1]=P[i];
FOR(j,2,k){
int maxright=0; ll sumleft=F[j-1][j-1];
FOR(i,j,n){
maxright = max(maxright,A[i]);
// cout<<i<<' '<<j<<' '<<sumleft<<' '<<maxright<<' '<<(F[i-1][j-1]+P[i-1]+A[i])<<endl;
if (sumleft+maxright < F[i-1][j-1]+A[i]) F[i][j]=sumleft+maxright;
else {
sumleft = F[i-1][j-1];
maxright = A[i];
F[i][j]=F[i-1][j-1]+A[i];
}
}
}
cout<<F[n][k];
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
448 KB |
Output is correct |
3 |
Correct |
3 ms |
448 KB |
Output is correct |
4 |
Correct |
2 ms |
448 KB |
Output is correct |
5 |
Correct |
2 ms |
528 KB |
Output is correct |
6 |
Correct |
2 ms |
548 KB |
Output is correct |
7 |
Correct |
3 ms |
764 KB |
Output is correct |
8 |
Correct |
2 ms |
764 KB |
Output is correct |
9 |
Correct |
2 ms |
832 KB |
Output is correct |
10 |
Correct |
2 ms |
832 KB |
Output is correct |
11 |
Incorrect |
2 ms |
832 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
832 KB |
Output is correct |
2 |
Correct |
3 ms |
848 KB |
Output is correct |
3 |
Correct |
2 ms |
848 KB |
Output is correct |
4 |
Correct |
2 ms |
848 KB |
Output is correct |
5 |
Correct |
2 ms |
848 KB |
Output is correct |
6 |
Correct |
2 ms |
848 KB |
Output is correct |
7 |
Correct |
2 ms |
848 KB |
Output is correct |
8 |
Correct |
3 ms |
848 KB |
Output is correct |
9 |
Correct |
2 ms |
848 KB |
Output is correct |
10 |
Correct |
2 ms |
908 KB |
Output is correct |
11 |
Incorrect |
2 ms |
908 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
908 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
12 ms |
9536 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |