#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pli pair<ll, int>
#define wr puts("----------------")
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<=b){a=b;return 1;}return 0;}
const int N = 1005;
const int K = 205;
int v[N], par[N], id[N][K];
ll dp[N][K];
int main(){
// freopen("file.txt", "r", stdin);
int n, k;
scanf("%d%d", &n, &k);
for(int i = 1; i <= n; ++i){
int x;
scanf("%d", &x);
v[i] = x;
}
for(int i = 1; i <= n; ++i)
par[i] = par[i-1]+v[i];
for(int i = 1; i <= n; ++i)
for(int j = 0; j < i; ++j)
for(int x = 1; x <= min(k, i); ++x)
if(umax(dp[i][x], dp[j][x-1]+(par[i]-par[j])*(par[n]-par[i])))
id[i][x] = j;
ll answer = 0;
for(int i = 1; i <= n; ++i)
umax(answer, dp[i][k]);
int d = 0, x = k;
for(int i = 1; i <= n; ++i)
if(dp[i][k] == answer){
d = i;
break;
}
vector<int> A;
while(x){
A.pb(d);
d = id[d][x];
--x;
}
printf("%lld\n", answer);
for(int i = k-1; i >= 0; --i)
printf("%d ", A[i]);
puts("");
return 0;
}
Compilation message
sequence.cpp: In function 'int main()':
sequence.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
21 | scanf("%d%d", &n, &k);
| ~~~~~^~~~~~~~~~~~~~~~
sequence.cpp:24:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
24 | scanf("%d", &x);
| ~~~~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
contestant found the optimal answer: 108 == 108 |
2 |
Correct |
0 ms |
348 KB |
contestant found the optimal answer: 999 == 999 |
3 |
Correct |
0 ms |
348 KB |
contestant found the optimal answer: 0 == 0 |
4 |
Correct |
0 ms |
348 KB |
contestant found the optimal answer: 1542524 == 1542524 |
5 |
Correct |
0 ms |
348 KB |
contestant found the optimal answer: 4500000000 == 4500000000 |
6 |
Correct |
0 ms |
344 KB |
contestant found the optimal answer: 1 == 1 |
7 |
Correct |
0 ms |
348 KB |
contestant found the optimal answer: 1 == 1 |
8 |
Correct |
0 ms |
348 KB |
contestant found the optimal answer: 1 == 1 |
9 |
Correct |
0 ms |
348 KB |
contestant found the optimal answer: 100400096 == 100400096 |
10 |
Correct |
1 ms |
344 KB |
contestant found the optimal answer: 900320000 == 900320000 |
11 |
Correct |
0 ms |
348 KB |
contestant found the optimal answer: 3698080248 == 3698080248 |
12 |
Correct |
0 ms |
348 KB |
contestant found the optimal answer: 3200320000 == 3200320000 |
13 |
Correct |
0 ms |
348 KB |
contestant found the optimal answer: 140072 == 140072 |
14 |
Correct |
0 ms |
348 KB |
contestant found the optimal answer: 376041456 == 376041456 |
15 |
Correct |
0 ms |
344 KB |
contestant found the optimal answer: 805 == 805 |
16 |
Correct |
1 ms |
440 KB |
contestant found the optimal answer: 900189994 == 900189994 |
17 |
Correct |
1 ms |
344 KB |
contestant found the optimal answer: 999919994 == 999919994 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
contestant found the optimal answer: 1093956 == 1093956 |
2 |
Correct |
0 ms |
348 KB |
contestant found the optimal answer: 302460000 == 302460000 |
3 |
Incorrect |
0 ms |
348 KB |
Integer 0 violates the range [1, 49] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
860 KB |
contestant found the optimal answer: 610590000 == 610590000 |
2 |
Correct |
1 ms |
860 KB |
contestant found the optimal answer: 311760000 == 311760000 |
3 |
Incorrect |
4 ms |
860 KB |
Integer 0 violates the range [1, 199] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
2652 KB |
contestant found the optimal answer: 21503404 == 21503404 |
2 |
Correct |
4 ms |
2648 KB |
contestant found the optimal answer: 140412195 == 140412195 |
3 |
Incorrect |
109 ms |
2632 KB |
declared answer doesn't correspond to the split scheme: declared = 391498272124, real = 49482974465404 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |