29682023-02-06 11:59:311478Csoportokba osztáscpp17Time limit exceeded 22/1002.599s6440 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);
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }

    vector<long long> 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-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
1Accepted3ms1828 KiB
2Accepted3ms2040 KiB
subtask20/5
3Time limit exceeded2.599s3576 KiB
4Time limit exceeded2.549s3696 KiB
5Time limit exceeded2.556s3840 KiB
subtask322/22
6Accepted59ms4920 KiB
7Accepted59ms5156 KiB
8Accepted59ms5372 KiB
9Accepted59ms5612 KiB
10Accepted59ms5792 KiB
11Accepted59ms5892 KiB
subtask40/34
12Accepted3ms4028 KiB
13Accepted3ms4184 KiB
14Accepted3ms4540 KiB
15Time limit exceeded2.599s5564 KiB
16Time limit exceeded2.588s5580 KiB
17Time limit exceeded2.559s5580 KiB
18Accepted4ms5616 KiB
19Accepted4ms5732 KiB
20Accepted4ms5640 KiB
21Time limit exceeded2.599s5948 KiB
22Time limit exceeded2.575s5900 KiB
23Time limit exceeded2.584s5896 KiB
subtask50/29
24Time limit exceeded2.578s5900 KiB
25Time limit exceeded2.561s5900 KiB
26Time limit exceeded2.532s6112 KiB
27Time limit exceeded2.559s6236 KiB
28Time limit exceeded2.552s6388 KiB
29Time limit exceeded2.53s6112 KiB
30Time limit exceeded2.543s6288 KiB
31Time limit exceeded2.561s6348 KiB
32Time limit exceeded2.563s6344 KiB
subtask60/10
33Time limit exceeded2.546s6440 KiB
34Time limit exceeded2.575s6320 KiB
35Time limit exceeded2.563s6340 KiB
36Time limit exceeded2.543s6396 KiB
37Time limit exceeded2.586s6436 KiB
38Time limit exceeded2.569s6260 KiB