29692023-02-06 12:06:431478Csoportokba osztáscpp17Time limit exceeded 22/1002.599s6688 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;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1960 KiB
2Accepted3ms2156 KiB
subtask20/5
3Time limit exceeded2.599s3656 KiB
4Time limit exceeded2.579s3712 KiB
5Time limit exceeded2.572s3980 KiB
subtask322/22
6Accepted59ms5156 KiB
7Accepted59ms5392 KiB
8Accepted59ms5456 KiB
9Accepted59ms5552 KiB
10Accepted59ms5764 KiB
11Accepted59ms5976 KiB
subtask40/34
12Accepted3ms4136 KiB
13Accepted3ms4376 KiB
14Accepted3ms4328 KiB
15Time limit exceeded2.599s5268 KiB
16Time limit exceeded2.572s5600 KiB
17Time limit exceeded2.556s5900 KiB
18Accepted4ms5552 KiB
19Accepted4ms5888 KiB
20Accepted4ms5792 KiB
21Time limit exceeded2.543s6316 KiB
22Time limit exceeded2.568s6224 KiB
23Time limit exceeded2.54s6268 KiB
subtask50/29
24Time limit exceeded2.575s6224 KiB
25Time limit exceeded2.568s6224 KiB
26Time limit exceeded2.565s6292 KiB
27Time limit exceeded2.555s6440 KiB
28Time limit exceeded2.565s6436 KiB
29Time limit exceeded2.569s6536 KiB
30Time limit exceeded2.536s6436 KiB
31Time limit exceeded2.552s6584 KiB
32Time limit exceeded2.548s6436 KiB
subtask60/10
33Time limit exceeded2.563s6368 KiB
34Time limit exceeded2.552s6448 KiB
35Time limit exceeded2.563s6380 KiB
36Time limit exceeded2.559s6576 KiB
37Time limit exceeded2.558s6688 KiB
38Time limit exceeded2.568s6564 KiB