27672023-01-23 09:23:19CattCsoportokba osztáscpp17Wrong answer 0/100146ms6440 KiB
#include <bits/stdc++.h>
using namespace std;
#define InTheNameOfGod ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
using ll = long long;

const int maxN = 2e5 + 5;
const int INF = 1e9 + 7;

int main() {
    int t = 1;
    //cin >> t;
    while(t--)
    {
        int n, k;
        cin >> n >> k;

        vector<int> prefSum(n+1, 0);

        vector<int> v(n);
        for(int i = 0; i < n; i++) {
            cin >> v[i];
            prefSum[i+1] = prefSum[i] + v[i];
        }
        
        set<int> leaders;
        leaders.insert(n-1);
        
        for(int j = 0; j < k-1; j++) {
            int last = 0;
            int maxi = -INF, ind = -1;
            auto it = leaders.begin();
            //cout << j << ": \n";
            for(int i = 0; i < n-1; i++) {
                //cout << i << ": " << last << ", " << (*it) << endl;
                if(leaders.find(i) != leaders.end()) {
                    last = i+1;
                    it++;
                    continue;
                }

                if((prefSum[i+1] - prefSum[last]) * (abs(v[i]) - abs(v[(*it)])) > maxi) {
                    maxi = (prefSum[i+1] - prefSum[last]) * (abs(v[i]) - abs(v[(*it)]));
                    ind = i;
                }
                /*cout << "val: " << (prefSum[i+1] - prefSum[last]) * (abs(v[i]) - v[(*it)]) << endl;
                cout << "maxi: " << maxi << ", " << ind << endl;*/
            }

            //cout << "-------\n";
            leaders.insert(ind);
        }
        
        int mo = 0, last = 0;
        for(int sz : leaders) {
            //cout << sz << ' ';
            mo += (prefSum[sz+1] - prefSum[last]) * abs(v[sz]);
            last = sz + 1;
        }
        //cout << "\n";
        cout << mo;
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1816 KiB
2Accepted2ms2156 KiB
subtask20/5
3Wrong answer37ms3624 KiB
4Wrong answer37ms3844 KiB
5Wrong answer37ms4048 KiB
subtask30/22
6Wrong answer4ms2812 KiB
7Wrong answer4ms2940 KiB
8Wrong answer4ms3068 KiB
9Wrong answer4ms3148 KiB
10Wrong answer4ms3260 KiB
11Wrong answer4ms3312 KiB
subtask40/34
12Wrong answer2ms3340 KiB
13Wrong answer2ms3476 KiB
14Wrong answer2ms3588 KiB
15Wrong answer143ms5180 KiB
16Wrong answer141ms5056 KiB
17Wrong answer142ms5332 KiB
18Wrong answer3ms3952 KiB
19Wrong answer2ms3972 KiB
20Wrong answer2ms3972 KiB
21Wrong answer142ms5316 KiB
22Wrong answer143ms5440 KiB
23Wrong answer141ms5524 KiB
subtask50/29
24Wrong answer143ms5644 KiB
25Wrong answer142ms5732 KiB
26Wrong answer143ms5808 KiB
27Wrong answer143ms5884 KiB
28Wrong answer138ms5808 KiB
29Wrong answer142ms5940 KiB
30Wrong answer142ms5928 KiB
31Wrong answer140ms6012 KiB
32Wrong answer140ms6016 KiB
subtask60/10
33Wrong answer145ms6092 KiB
34Wrong answer144ms6180 KiB
35Wrong answer146ms6008 KiB
36Wrong answer144ms6012 KiB
37Wrong answer144ms6356 KiB
38Wrong answer144ms6440 KiB