27652023-01-23 09:19:22CattCsoportokba osztáscpp17Wrong answer 0/100108ms6528 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() {

#pragma region
#ifndef ONLINE_JUDGE
   freopen("../input.txt", "r", stdin);
   freopen("../output.txt", "w", stdout);
#endif

   InTheNameOfGod;
#pragma endregion
    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
1Accepted3ms1912 KiB
2Accepted2ms2064 KiB
subtask20/5
3Wrong answer13ms3480 KiB
4Wrong answer13ms3800 KiB
5Wrong answer14ms3948 KiB
subtask30/22
6Wrong answer4ms2696 KiB
7Wrong answer4ms2912 KiB
8Wrong answer4ms3112 KiB
9Wrong answer4ms3272 KiB
10Wrong answer4ms3276 KiB
11Wrong answer3ms3360 KiB
subtask40/34
12Wrong answer2ms3392 KiB
13Wrong answer2ms3464 KiB
14Wrong answer2ms3592 KiB
15Wrong answer104ms5008 KiB
16Wrong answer103ms5260 KiB
17Wrong answer105ms5612 KiB
18Wrong answer2ms4276 KiB
19Wrong answer3ms4132 KiB
20Wrong answer2ms4128 KiB
21Wrong answer104ms5588 KiB
22Wrong answer105ms5532 KiB
23Wrong answer104ms5536 KiB
subtask50/29
24Wrong answer104ms5536 KiB
25Wrong answer104ms5792 KiB
26Wrong answer104ms5844 KiB
27Wrong answer104ms5740 KiB
28Wrong answer104ms6008 KiB
29Wrong answer104ms6104 KiB
30Wrong answer105ms6132 KiB
31Wrong answer103ms6080 KiB
32Wrong answer104ms6140 KiB
subtask60/10
33Wrong answer104ms6136 KiB
34Wrong answer108ms6332 KiB
35Wrong answer108ms6528 KiB
36Wrong answer107ms6500 KiB
37Wrong answer105ms6460 KiB
38Wrong answer107ms6456 KiB