29662023-02-06 11:50:341478Csoportokba osztáscpp17Time limit exceeded 0/1002.599s5168 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;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1700 KiB
2Accepted3ms1860 KiB
subtask20/5
3Time limit exceeded2.598s2492 KiB
4Time limit exceeded2.575s2580 KiB
5Time limit exceeded2.572s2776 KiB
subtask30/22
6Wrong answer65ms4384 KiB
7Wrong answer65ms4396 KiB
8Wrong answer65ms4340 KiB
9Wrong answer65ms4336 KiB
10Wrong answer65ms4336 KiB
11Wrong answer65ms4340 KiB
subtask40/34
12Accepted3ms3508 KiB
13Accepted3ms3544 KiB
14Accepted3ms3620 KiB
15Time limit exceeded2.599s3272 KiB
16Time limit exceeded2.536s3360 KiB
17Time limit exceeded2.584s3704 KiB
18Accepted4ms4464 KiB
19Accepted4ms4596 KiB
20Accepted4ms4460 KiB
21Time limit exceeded2.599s3928 KiB
22Time limit exceeded2.53s4080 KiB
23Time limit exceeded2.586s3956 KiB
subtask50/29
24Time limit exceeded2.565s4008 KiB
25Time limit exceeded2.561s4008 KiB
26Time limit exceeded2.556s4016 KiB
27Time limit exceeded2.536s4080 KiB
28Time limit exceeded2.581s3928 KiB
29Time limit exceeded2.572s4068 KiB
30Time limit exceeded2.563s4444 KiB
31Time limit exceeded2.572s4700 KiB
32Time limit exceeded2.575s4756 KiB
subtask60/10
33Time limit exceeded2.579s4944 KiB
34Time limit exceeded2.54s5000 KiB
35Time limit exceeded2.575s5160 KiB
36Time limit exceeded2.562s5020 KiB
37Time limit exceeded2.561s5060 KiB
38Time limit exceeded2.555s5168 KiB