#include <iostream>
using namespace std;
int main()
{
int n, k;
cin >> n >> k;
int a[n+1];
a[0] = 0;
for(int i = 1; i <= n; i++)
{
cin >> a[i];
a[i] += a[i-1];
}
int dp[n+1][k+1];
int prev[n+1][k+1];
for(int i = 1; i <= n; i++)
{
for(int l = 1; l < n && l <= k; l++)
{
dp[i][l] = 0;
prev[i][l] = 0;
for(int j = l; j < i; j++)
{
if(dp[j][l-1] + a[j] * (a[i] - a[j]) > dp[i][l])
{
dp[i][l] = dp[j][l-1] + a[j] * (a[i] - a[j]);
prev[i][l] = j;
}
}
}
}
cout << dp[n][k] << '\n';
int temp = n;
for(int l = k; l >= 1; l--)
{
cout << prev[temp][l] << ' ';
temp = prev[temp][l];
}
cout << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
declared answer doesn't correspond to the split scheme: declared = 8148748, real = 108 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
declared answer doesn't correspond to the split scheme: declared = 9263598, real = 1093606 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
contestant found the optimal answer: 610590000 == 610590000 |
2 |
Correct |
1 ms |
364 KB |
contestant found the optimal answer: 311760000 == 311760000 |
3 |
Incorrect |
4 ms |
620 KB |
Integer 0 violates the range [1, 199] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
364 KB |
declared answer doesn't correspond to the split scheme: declared = 28379739, real = 20233307 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
376 ms |
768 KB |
contestant found the optimal answer: 1818678304 == 1818678304 |
2 |
Correct |
202 ms |
772 KB |
contestant found the optimal answer: 1326260195 == 1326260195 |
3 |
Execution timed out |
2076 ms |
5744 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2075 ms |
1836 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |