2969 | 2023-02-06 12:06:43 | 1478 | Csoportokba osztás | cpp17 | Time limit exceeded 22/100 | 2.599s | 6688 KiB |
#include <bits/stdc++.h>
using namespace std;
long long dp[101][100001];
int main()
{
//ifstream cin("in.txt");
int n;
cin >> n;
int l;
cin >> l;
vector<long long> a(n+1);
vector<long long> pS(n+1);
for(int i = 1; i <= n; i++){
cin >> a[i];
pS[i] = pS[i-1] + a[i];
}
/*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-l+i; j++){
long long 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 | 1960 KiB | ||||
2 | Accepted | 3ms | 2156 KiB | ||||
subtask2 | 0/5 | ||||||
3 | Time limit exceeded | 2.599s | 3656 KiB | ||||
4 | Time limit exceeded | 2.579s | 3712 KiB | ||||
5 | Time limit exceeded | 2.572s | 3980 KiB | ||||
subtask3 | 22/22 | ||||||
6 | Accepted | 59ms | 5156 KiB | ||||
7 | Accepted | 59ms | 5392 KiB | ||||
8 | Accepted | 59ms | 5456 KiB | ||||
9 | Accepted | 59ms | 5552 KiB | ||||
10 | Accepted | 59ms | 5764 KiB | ||||
11 | Accepted | 59ms | 5976 KiB | ||||
subtask4 | 0/34 | ||||||
12 | Accepted | 3ms | 4136 KiB | ||||
13 | Accepted | 3ms | 4376 KiB | ||||
14 | Accepted | 3ms | 4328 KiB | ||||
15 | Time limit exceeded | 2.599s | 5268 KiB | ||||
16 | Time limit exceeded | 2.572s | 5600 KiB | ||||
17 | Time limit exceeded | 2.556s | 5900 KiB | ||||
18 | Accepted | 4ms | 5552 KiB | ||||
19 | Accepted | 4ms | 5888 KiB | ||||
20 | Accepted | 4ms | 5792 KiB | ||||
21 | Time limit exceeded | 2.543s | 6316 KiB | ||||
22 | Time limit exceeded | 2.568s | 6224 KiB | ||||
23 | Time limit exceeded | 2.54s | 6268 KiB | ||||
subtask5 | 0/29 | ||||||
24 | Time limit exceeded | 2.575s | 6224 KiB | ||||
25 | Time limit exceeded | 2.568s | 6224 KiB | ||||
26 | Time limit exceeded | 2.565s | 6292 KiB | ||||
27 | Time limit exceeded | 2.555s | 6440 KiB | ||||
28 | Time limit exceeded | 2.565s | 6436 KiB | ||||
29 | Time limit exceeded | 2.569s | 6536 KiB | ||||
30 | Time limit exceeded | 2.536s | 6436 KiB | ||||
31 | Time limit exceeded | 2.552s | 6584 KiB | ||||
32 | Time limit exceeded | 2.548s | 6436 KiB | ||||
subtask6 | 0/10 | ||||||
33 | Time limit exceeded | 2.563s | 6368 KiB | ||||
34 | Time limit exceeded | 2.552s | 6448 KiB | ||||
35 | Time limit exceeded | 2.563s | 6380 KiB | ||||
36 | Time limit exceeded | 2.559s | 6576 KiB | ||||
37 | Time limit exceeded | 2.558s | 6688 KiB | ||||
38 | Time limit exceeded | 2.568s | 6564 KiB |