#include <vector>
#include <bits/stdc++.h>
typedef int 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[10001][201];
vector<ll> prevs[10001][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,10001)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){
vector<ll> sus = prevs[n][k];
if (k != sus[1]) cout << n << " ";
n = sus[0];
k = sus[1];
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
55388 KB |
contestant found the optimal answer: 108 == 108 |
2 |
Correct |
20 ms |
55384 KB |
contestant found the optimal answer: 999 == 999 |
3 |
Runtime error |
58 ms |
112052 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
55388 KB |
contestant found the optimal answer: 1093956 == 1093956 |
2 |
Correct |
23 ms |
55388 KB |
contestant found the optimal answer: 302460000 == 302460000 |
3 |
Runtime error |
61 ms |
112212 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
55388 KB |
contestant found the optimal answer: 610590000 == 610590000 |
2 |
Correct |
24 ms |
55384 KB |
contestant found the optimal answer: 311760000 == 311760000 |
3 |
Runtime error |
71 ms |
114512 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
55388 KB |
contestant found the optimal answer: 21503404 == 21503404 |
2 |
Correct |
24 ms |
55580 KB |
contestant found the optimal answer: 140412195 == 140412195 |
3 |
Runtime error |
227 ms |
124688 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
639 ms |
56316 KB |
contestant found the optimal answer: 1818678304 == 1818678304 |
2 |
Correct |
350 ms |
56340 KB |
contestant found the optimal answer: 1326260195 == 1326260195 |
3 |
Execution timed out |
2082 ms |
77444 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
476 ms |
115700 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |