2767 | 2023-01-23 09:23:19 | Catt | Csoportokba osztás | cpp17 | Wrong answer 0/100 | 146ms | 6440 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;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1816 KiB | ||||
2 | Accepted | 2ms | 2156 KiB | ||||
subtask2 | 0/5 | ||||||
3 | Wrong answer | 37ms | 3624 KiB | ||||
4 | Wrong answer | 37ms | 3844 KiB | ||||
5 | Wrong answer | 37ms | 4048 KiB | ||||
subtask3 | 0/22 | ||||||
6 | Wrong answer | 4ms | 2812 KiB | ||||
7 | Wrong answer | 4ms | 2940 KiB | ||||
8 | Wrong answer | 4ms | 3068 KiB | ||||
9 | Wrong answer | 4ms | 3148 KiB | ||||
10 | Wrong answer | 4ms | 3260 KiB | ||||
11 | Wrong answer | 4ms | 3312 KiB | ||||
subtask4 | 0/34 | ||||||
12 | Wrong answer | 2ms | 3340 KiB | ||||
13 | Wrong answer | 2ms | 3476 KiB | ||||
14 | Wrong answer | 2ms | 3588 KiB | ||||
15 | Wrong answer | 143ms | 5180 KiB | ||||
16 | Wrong answer | 141ms | 5056 KiB | ||||
17 | Wrong answer | 142ms | 5332 KiB | ||||
18 | Wrong answer | 3ms | 3952 KiB | ||||
19 | Wrong answer | 2ms | 3972 KiB | ||||
20 | Wrong answer | 2ms | 3972 KiB | ||||
21 | Wrong answer | 142ms | 5316 KiB | ||||
22 | Wrong answer | 143ms | 5440 KiB | ||||
23 | Wrong answer | 141ms | 5524 KiB | ||||
subtask5 | 0/29 | ||||||
24 | Wrong answer | 143ms | 5644 KiB | ||||
25 | Wrong answer | 142ms | 5732 KiB | ||||
26 | Wrong answer | 143ms | 5808 KiB | ||||
27 | Wrong answer | 143ms | 5884 KiB | ||||
28 | Wrong answer | 138ms | 5808 KiB | ||||
29 | Wrong answer | 142ms | 5940 KiB | ||||
30 | Wrong answer | 142ms | 5928 KiB | ||||
31 | Wrong answer | 140ms | 6012 KiB | ||||
32 | Wrong answer | 140ms | 6016 KiB | ||||
subtask6 | 0/10 | ||||||
33 | Wrong answer | 145ms | 6092 KiB | ||||
34 | Wrong answer | 144ms | 6180 KiB | ||||
35 | Wrong answer | 146ms | 6008 KiB | ||||
36 | Wrong answer | 144ms | 6012 KiB | ||||
37 | Wrong answer | 144ms | 6356 KiB | ||||
38 | Wrong answer | 144ms | 6440 KiB |