2966 | 2023-02-06 11:50:34 | 1478 | Csoportokba osztás | cpp17 | Time limit exceeded 0/100 | 2.599s | 5168 KiB |
#include <bits/stdc++.h>
using namespace std;
int dp[101][100001];
int main()
{
//ifstream cin("in.txt");
int n;
cin >> n;
int l;
cin >> l;
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 <= l; 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[l][n];
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1700 KiB | ||||
2 | Accepted | 3ms | 1860 KiB | ||||
subtask2 | 0/5 | ||||||
3 | Time limit exceeded | 2.598s | 2492 KiB | ||||
4 | Time limit exceeded | 2.575s | 2580 KiB | ||||
5 | Time limit exceeded | 2.572s | 2776 KiB | ||||
subtask3 | 0/22 | ||||||
6 | Wrong answer | 65ms | 4384 KiB | ||||
7 | Wrong answer | 65ms | 4396 KiB | ||||
8 | Wrong answer | 65ms | 4340 KiB | ||||
9 | Wrong answer | 65ms | 4336 KiB | ||||
10 | Wrong answer | 65ms | 4336 KiB | ||||
11 | Wrong answer | 65ms | 4340 KiB | ||||
subtask4 | 0/34 | ||||||
12 | Accepted | 3ms | 3508 KiB | ||||
13 | Accepted | 3ms | 3544 KiB | ||||
14 | Accepted | 3ms | 3620 KiB | ||||
15 | Time limit exceeded | 2.599s | 3272 KiB | ||||
16 | Time limit exceeded | 2.536s | 3360 KiB | ||||
17 | Time limit exceeded | 2.584s | 3704 KiB | ||||
18 | Accepted | 4ms | 4464 KiB | ||||
19 | Accepted | 4ms | 4596 KiB | ||||
20 | Accepted | 4ms | 4460 KiB | ||||
21 | Time limit exceeded | 2.599s | 3928 KiB | ||||
22 | Time limit exceeded | 2.53s | 4080 KiB | ||||
23 | Time limit exceeded | 2.586s | 3956 KiB | ||||
subtask5 | 0/29 | ||||||
24 | Time limit exceeded | 2.565s | 4008 KiB | ||||
25 | Time limit exceeded | 2.561s | 4008 KiB | ||||
26 | Time limit exceeded | 2.556s | 4016 KiB | ||||
27 | Time limit exceeded | 2.536s | 4080 KiB | ||||
28 | Time limit exceeded | 2.581s | 3928 KiB | ||||
29 | Time limit exceeded | 2.572s | 4068 KiB | ||||
30 | Time limit exceeded | 2.563s | 4444 KiB | ||||
31 | Time limit exceeded | 2.572s | 4700 KiB | ||||
32 | Time limit exceeded | 2.575s | 4756 KiB | ||||
subtask6 | 0/10 | ||||||
33 | Time limit exceeded | 2.579s | 4944 KiB | ||||
34 | Time limit exceeded | 2.54s | 5000 KiB | ||||
35 | Time limit exceeded | 2.575s | 5160 KiB | ||||
36 | Time limit exceeded | 2.562s | 5020 KiB | ||||
37 | Time limit exceeded | 2.561s | 5060 KiB | ||||
38 | Time limit exceeded | 2.555s | 5168 KiB |