29672023-02-06 11:55:561478Csoportokba osztáscpp17Time limit exceeded 22/1002.599s6364 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; 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
2Accepted3ms2024 KiB
subtask20/5
3Time limit exceeded2.599s3552 KiB
4Time limit exceeded2.575s3848 KiB
5Time limit exceeded2.578s3928 KiB
subtask322/22
6Accepted65ms5052 KiB
7Accepted65ms5392 KiB
8Accepted65ms5336 KiB
9Accepted65ms5660 KiB
10Accepted65ms5992 KiB
11Accepted65ms6080 KiB
subtask40/34
12Accepted3ms4216 KiB
13Accepted3ms4340 KiB
14Accepted3ms4432 KiB
15Time limit exceeded2.599s5132 KiB
16Time limit exceeded2.565s5132 KiB
17Time limit exceeded2.548s5356 KiB
18Accepted4ms5168 KiB
19Accepted4ms5344 KiB
20Accepted4ms5472 KiB
21Time limit exceeded2.599s5876 KiB
22Time limit exceeded2.568s5828 KiB
23Time limit exceeded2.586s5848 KiB
subtask50/29
24Time limit exceeded2.575s5756 KiB
25Time limit exceeded2.581s5988 KiB
26Time limit exceeded2.545s5756 KiB
27Time limit exceeded2.569s5824 KiB
28Time limit exceeded2.563s5944 KiB
29Time limit exceeded2.549s6124 KiB
30Time limit exceeded2.536s6000 KiB
31Time limit exceeded2.563s6208 KiB
32Time limit exceeded2.572s6188 KiB
subtask60/10
33Time limit exceeded2.568s6176 KiB
34Time limit exceeded2.562s6176 KiB
35Time limit exceeded2.568s6228 KiB
36Time limit exceeded2.572s6236 KiB
37Time limit exceeded2.575s6340 KiB
38Time limit exceeded2.568s6364 KiB