#include <vector>
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,x,y) for(ll i=x; i<y; i++)
#define FORNEG(i,x,y) for(ll i=x; i>y; i--)
using namespace std;
ll dp[1001][201];
vector<ll> prevs[1001][201];
int main(){
deque<vector<ll>> sus;
ll n,k;
cin >> n >> k;
vector<ll> arr(n);
vector<ll> pref(n);
FOR(i,0,n) cin >> arr[i];
pref[0] = arr[0];
FOR(i,1,n) pref[i] = pref[i-1]+arr[i];
FOR(i,0,1001)FOR(j,0,201) dp[i][j] = 0;
FOR(i,1,n+1){
FOR(j,1,k+1){
FOR(m,0, i){
ll temp = dp[m][j-1] + (pref[n-1] - pref[i-1]) * (pref[i-1]-pref[m]+arr[m]);
if (dp[i][j] < temp){
dp[i][j] = temp;
prevs[i][j] = {m, j-1};
}
}
if (dp[i-1][j] > dp[i][j]){
dp[i][j] = dp[i-1][j];
prevs[i][j] = {i-1, j};
}
}
}
cout << dp[n][k] << endl;
while (k != 0 || prevs[n][k].size()!=0){
vector<ll> sus = prevs[n][k];
if (k != sus[1]) cout << n << " ";
n = sus[0];
k = sus[1];
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6488 KB |
contestant found the optimal answer: 108 == 108 |
2 |
Correct |
2 ms |
6492 KB |
contestant found the optimal answer: 999 == 999 |
3 |
Runtime error |
6 ms |
13092 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6488 KB |
contestant found the optimal answer: 1093956 == 1093956 |
2 |
Correct |
2 ms |
6488 KB |
contestant found the optimal answer: 302460000 == 302460000 |
3 |
Correct |
3 ms |
6748 KB |
contestant found the optimal answer: 122453454361 == 122453454361 |
4 |
Correct |
2 ms |
6492 KB |
contestant found the optimal answer: 93663683509 == 93663683509 |
5 |
Correct |
2 ms |
6748 KB |
contestant found the optimal answer: 1005304678 == 1005304678 |
6 |
Correct |
3 ms |
6700 KB |
contestant found the optimal answer: 933702 == 933702 |
7 |
Correct |
2 ms |
6748 KB |
contestant found the optimal answer: 25082842857 == 25082842857 |
8 |
Correct |
2 ms |
6748 KB |
contestant found the optimal answer: 687136 == 687136 |
9 |
Correct |
2 ms |
6528 KB |
contestant found the optimal answer: 27295930079 == 27295930079 |
10 |
Correct |
3 ms |
6748 KB |
contestant found the optimal answer: 29000419931 == 29000419931 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6748 KB |
contestant found the optimal answer: 610590000 == 610590000 |
2 |
Correct |
2 ms |
6744 KB |
contestant found the optimal answer: 311760000 == 311760000 |
3 |
Correct |
38 ms |
7820 KB |
contestant found the optimal answer: 1989216017013 == 1989216017013 |
4 |
Correct |
3 ms |
6748 KB |
contestant found the optimal answer: 1499437552673 == 1499437552673 |
5 |
Correct |
28 ms |
7548 KB |
contestant found the optimal answer: 1019625819 == 1019625819 |
6 |
Runtime error |
34 ms |
15440 KB |
Execution killed with signal 11 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
6748 KB |
contestant found the optimal answer: 21503404 == 21503404 |
2 |
Correct |
5 ms |
6748 KB |
contestant found the optimal answer: 140412195 == 140412195 |
3 |
Correct |
852 ms |
12880 KB |
contestant found the optimal answer: 49729674225461 == 49729674225461 |
4 |
Correct |
9 ms |
6744 KB |
contestant found the optimal answer: 37485571387523 == 37485571387523 |
5 |
Correct |
756 ms |
12804 KB |
contestant found the optimal answer: 679388326 == 679388326 |
6 |
Correct |
640 ms |
11856 KB |
contestant found the optimal answer: 4699030287 == 4699030287 |
7 |
Correct |
863 ms |
12888 KB |
contestant found the optimal answer: 12418819758185 == 12418819758185 |
8 |
Correct |
850 ms |
12984 KB |
contestant found the optimal answer: 31093317350 == 31093317350 |
9 |
Correct |
149 ms |
7976 KB |
contestant found the optimal answer: 12194625429236 == 12194625429236 |
10 |
Correct |
308 ms |
9140 KB |
contestant found the optimal answer: 12345131038664 == 12345131038664 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
14 ms |
13812 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
22 ms |
16476 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |