27662023-01-23 09:20:17CattCsoportokba osztáscpp17Wrong answer 0/100150ms6276 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]) - v[(*it)]) > maxi) {
                    maxi = (prefSum[i+1] - prefSum[last]) * (abs(v[i]) - 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) {
            mo += (prefSum[sz+1] - prefSum[last]) * abs(v[sz]);
            last = sz + 1;
        }
        cout << mo;
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1816 KiB
2Accepted2ms2056 KiB
subtask20/5
3Wrong answer35ms3652 KiB
4Wrong answer35ms3720 KiB
5Wrong answer37ms3848 KiB
subtask30/22
6Wrong answer4ms2712 KiB
7Wrong answer4ms2920 KiB
8Wrong answer4ms3264 KiB
9Wrong answer4ms3132 KiB
10Wrong answer4ms3204 KiB
11Wrong answer4ms3372 KiB
subtask40/34
12Wrong answer2ms3528 KiB
13Wrong answer2ms3672 KiB
14Wrong answer2ms3784 KiB
15Wrong answer144ms5268 KiB
16Wrong answer143ms5432 KiB
17Wrong answer143ms5592 KiB
18Wrong answer2ms4336 KiB
19Wrong answer2ms4444 KiB
20Wrong answer3ms4456 KiB
21Wrong answer144ms5788 KiB
22Wrong answer145ms5788 KiB
23Wrong answer143ms5872 KiB
subtask50/29
24Wrong answer145ms5784 KiB
25Wrong answer143ms5788 KiB
26Wrong answer143ms5868 KiB
27Wrong answer144ms5788 KiB
28Wrong answer142ms5864 KiB
29Wrong answer143ms5952 KiB
30Wrong answer144ms5952 KiB
31Wrong answer142ms5952 KiB
32Wrong answer143ms5948 KiB
subtask60/10
33Wrong answer143ms6084 KiB
34Wrong answer150ms6156 KiB
35Wrong answer145ms6068 KiB
36Wrong answer145ms6276 KiB
37Wrong answer145ms6268 KiB
38Wrong answer146ms6276 KiB