29652023-02-06 11:46:381478Csoportokba osztáscpp17Time limit exceeded 0/1002.599s5528 KiB
#include <bits/stdc++.h>

using namespace std;

int dp[101][100001];

int main()
{

    //ifstream cin("in.txt");

    int n;
    cin >> n;
    int k;
    cin >> k;

    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 <= k; 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[k][n];



    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1832 KiB
2Accepted3ms2020 KiB
subtask20/5
3Time limit exceeded2.599s2460 KiB
4Time limit exceeded2.572s2732 KiB
5Time limit exceeded2.513s2940 KiB
subtask30/22
6Wrong answer65ms4544 KiB
7Wrong answer65ms4948 KiB
8Wrong answer65ms4892 KiB
9Wrong answer65ms5084 KiB
10Wrong answer64ms5320 KiB
11Wrong answer64ms5256 KiB
subtask40/34
12Accepted3ms4216 KiB
13Accepted3ms4416 KiB
14Accepted3ms4312 KiB
15Time limit exceeded2.599s4168 KiB
16Time limit exceeded2.561s4164 KiB
17Time limit exceeded2.555s4424 KiB
18Accepted4ms5188 KiB
19Accepted4ms5304 KiB
20Accepted4ms5192 KiB
21Time limit exceeded2.599s4812 KiB
22Time limit exceeded2.551s4832 KiB
23Time limit exceeded2.571s4988 KiB
subtask50/29
24Time limit exceeded2.568s4932 KiB
25Time limit exceeded2.563s5076 KiB
26Time limit exceeded2.568s4984 KiB
27Time limit exceeded2.588s5000 KiB
28Time limit exceeded2.568s5216 KiB
29Time limit exceeded2.549s5432 KiB
30Time limit exceeded2.552s5476 KiB
31Time limit exceeded2.579s5384 KiB
32Time limit exceeded2.559s5528 KiB
subtask60/10
33Time limit exceeded2.572s5396 KiB
34Time limit exceeded2.571s5524 KiB
35Time limit exceeded2.578s5380 KiB
36Time limit exceeded2.556s5328 KiB
37Time limit exceeded2.581s5452 KiB
38Time limit exceeded2.578s5472 KiB