2965 | 2023-02-06 11:46:38 | 1478 | Csoportokba osztás | cpp17 | Time limit exceeded 0/100 | 2.599s | 5528 KiB |
#include <bits/stdc++.h>
using namespace std;
int dp[101][100001];
int main()
{
//ifstream cin("in.txt");
int n;
cin >> n;
int k;
cin >> k;
vector<int> a(n+1);
for(int i = 1; i <= n; i++){
cin >> a[i];
}
vector<int> pS(n+1);
for(int i = 1; i <= n; i++){
pS[i] = pS[i-1] + a[i];
//cout << pS[i] << " ";
}
//cout << '\n';
/*for(int i = 1; i <= n; i++){
dp[1][i] = pS[i] * a[i];
}*/
for(int i = 1; i <= k; i++){
//cout << i <<": ";
for(int j = i; j <= n; j++){
int maxi = 0;
for(int k = i-1; k <= j-1; k++){
//cout << dp[i-1][k] + (pS[j] - pS[k]) * abs(a[j]) << " ";
maxi = max(dp[i-1][k] + (pS[j] - pS[k]) * abs(a[j]), maxi);
}
dp[i][j] = maxi;
//cout << '\n';
}
//cout << '\n';
}
cout << dp[k][n];
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1832 KiB | ||||
2 | Accepted | 3ms | 2020 KiB | ||||
subtask2 | 0/5 | ||||||
3 | Time limit exceeded | 2.599s | 2460 KiB | ||||
4 | Time limit exceeded | 2.572s | 2732 KiB | ||||
5 | Time limit exceeded | 2.513s | 2940 KiB | ||||
subtask3 | 0/22 | ||||||
6 | Wrong answer | 65ms | 4544 KiB | ||||
7 | Wrong answer | 65ms | 4948 KiB | ||||
8 | Wrong answer | 65ms | 4892 KiB | ||||
9 | Wrong answer | 65ms | 5084 KiB | ||||
10 | Wrong answer | 64ms | 5320 KiB | ||||
11 | Wrong answer | 64ms | 5256 KiB | ||||
subtask4 | 0/34 | ||||||
12 | Accepted | 3ms | 4216 KiB | ||||
13 | Accepted | 3ms | 4416 KiB | ||||
14 | Accepted | 3ms | 4312 KiB | ||||
15 | Time limit exceeded | 2.599s | 4168 KiB | ||||
16 | Time limit exceeded | 2.561s | 4164 KiB | ||||
17 | Time limit exceeded | 2.555s | 4424 KiB | ||||
18 | Accepted | 4ms | 5188 KiB | ||||
19 | Accepted | 4ms | 5304 KiB | ||||
20 | Accepted | 4ms | 5192 KiB | ||||
21 | Time limit exceeded | 2.599s | 4812 KiB | ||||
22 | Time limit exceeded | 2.551s | 4832 KiB | ||||
23 | Time limit exceeded | 2.571s | 4988 KiB | ||||
subtask5 | 0/29 | ||||||
24 | Time limit exceeded | 2.568s | 4932 KiB | ||||
25 | Time limit exceeded | 2.563s | 5076 KiB | ||||
26 | Time limit exceeded | 2.568s | 4984 KiB | ||||
27 | Time limit exceeded | 2.588s | 5000 KiB | ||||
28 | Time limit exceeded | 2.568s | 5216 KiB | ||||
29 | Time limit exceeded | 2.549s | 5432 KiB | ||||
30 | Time limit exceeded | 2.552s | 5476 KiB | ||||
31 | Time limit exceeded | 2.579s | 5384 KiB | ||||
32 | Time limit exceeded | 2.559s | 5528 KiB | ||||
subtask6 | 0/10 | ||||||
33 | Time limit exceeded | 2.572s | 5396 KiB | ||||
34 | Time limit exceeded | 2.571s | 5524 KiB | ||||
35 | Time limit exceeded | 2.578s | 5380 KiB | ||||
36 | Time limit exceeded | 2.556s | 5328 KiB | ||||
37 | Time limit exceeded | 2.581s | 5452 KiB | ||||
38 | Time limit exceeded | 2.578s | 5472 KiB |