#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define ios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz size()
using namespace std;
const ll N=1e6+7, M=1e9+7;
ll a[N];
pair <ll, vector <int>> memo[1005][205];
void solve()
{
int n, k;
cin >> n >> k;
ll sum=0;
for (int i=1;i<=n;i++) cin >> a[i], sum+=a[i];
auto dp = [&] (auto& dp, int i, int k, ll sum) -> pair <ll,vector <int>> {
vector <int> vc;
if (k <= 0 || i >= n+1) return {0, vc};
if (memo[i][k].ff != -1) return memo[i][k];
ll cur=0, ans=0;
for (int j=i;j<=n;j++){
sum-=a[j], cur+=a[j];
pair <ll, vector <int>> res=dp(dp, j+1, k-1, sum);
if (ans < sum*cur+res.ff){
vc.clear();
vc.push_back(j);
for (auto l:res.ss) vc.push_back(l);
ans=sum*cur+res.ff;
}
}
memo[i][k]=make_pair(ans, vc);
return {ans, vc};
};
for (int i=0;i<=n;i++){
for (int j=0;j<=k;j++) memo[i][j].ff=-1;
}
pair <ll, vector <int>> res=dp(dp, 1, k, sum);
cout << res.ff <<"\n";
for (auto l:res.ss) cout << l <<" ";
return ;
}
int main(){
ios;
int t=1;
// cin >> t;
while (t--){
solve();
cout << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
6776 KB |
contestant found the optimal answer: 108 == 108 |
2 |
Correct |
3 ms |
6784 KB |
contestant found the optimal answer: 999 == 999 |
3 |
Incorrect |
4 ms |
6740 KB |
Unexpected end of file - int32 expected |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
6740 KB |
contestant found the optimal answer: 1093956 == 1093956 |
2 |
Correct |
4 ms |
6780 KB |
contestant found the optimal answer: 302460000 == 302460000 |
3 |
Correct |
5 ms |
6780 KB |
contestant found the optimal answer: 122453454361 == 122453454361 |
4 |
Correct |
4 ms |
6740 KB |
contestant found the optimal answer: 93663683509 == 93663683509 |
5 |
Correct |
4 ms |
6780 KB |
contestant found the optimal answer: 1005304678 == 1005304678 |
6 |
Correct |
4 ms |
6776 KB |
contestant found the optimal answer: 933702 == 933702 |
7 |
Correct |
5 ms |
6740 KB |
contestant found the optimal answer: 25082842857 == 25082842857 |
8 |
Correct |
5 ms |
6780 KB |
contestant found the optimal answer: 687136 == 687136 |
9 |
Correct |
5 ms |
6780 KB |
contestant found the optimal answer: 27295930079 == 27295930079 |
10 |
Correct |
4 ms |
6740 KB |
contestant found the optimal answer: 29000419931 == 29000419931 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
6740 KB |
contestant found the optimal answer: 610590000 == 610590000 |
2 |
Correct |
4 ms |
6780 KB |
contestant found the optimal answer: 311760000 == 311760000 |
3 |
Correct |
77 ms |
12168 KB |
contestant found the optimal answer: 1989216017013 == 1989216017013 |
4 |
Correct |
6 ms |
6784 KB |
contestant found the optimal answer: 1499437552673 == 1499437552673 |
5 |
Correct |
66 ms |
11032 KB |
contestant found the optimal answer: 1019625819 == 1019625819 |
6 |
Correct |
65 ms |
12000 KB |
contestant found the optimal answer: 107630884 == 107630884 |
7 |
Correct |
62 ms |
12168 KB |
contestant found the optimal answer: 475357671774 == 475357671774 |
8 |
Correct |
30 ms |
7504 KB |
contestant found the optimal answer: 193556962 == 193556962 |
9 |
Correct |
20 ms |
7032 KB |
contestant found the optimal answer: 482389919803 == 482389919803 |
10 |
Correct |
41 ms |
7864 KB |
contestant found the optimal answer: 490686959791 == 490686959791 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
6812 KB |
contestant found the optimal answer: 21503404 == 21503404 |
2 |
Correct |
21 ms |
6752 KB |
contestant found the optimal answer: 140412195 == 140412195 |
3 |
Execution timed out |
2080 ms |
39104 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
23 ms |
23764 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
26 ms |
24364 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |