2765 | 2023-01-23 09:19:22 | Catt | Csoportokba osztás | cpp17 | Wrong answer 0/100 | 108ms | 6528 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;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1912 KiB | ||||
2 | Accepted | 2ms | 2064 KiB | ||||
subtask2 | 0/5 | ||||||
3 | Wrong answer | 13ms | 3480 KiB | ||||
4 | Wrong answer | 13ms | 3800 KiB | ||||
5 | Wrong answer | 14ms | 3948 KiB | ||||
subtask3 | 0/22 | ||||||
6 | Wrong answer | 4ms | 2696 KiB | ||||
7 | Wrong answer | 4ms | 2912 KiB | ||||
8 | Wrong answer | 4ms | 3112 KiB | ||||
9 | Wrong answer | 4ms | 3272 KiB | ||||
10 | Wrong answer | 4ms | 3276 KiB | ||||
11 | Wrong answer | 3ms | 3360 KiB | ||||
subtask4 | 0/34 | ||||||
12 | Wrong answer | 2ms | 3392 KiB | ||||
13 | Wrong answer | 2ms | 3464 KiB | ||||
14 | Wrong answer | 2ms | 3592 KiB | ||||
15 | Wrong answer | 104ms | 5008 KiB | ||||
16 | Wrong answer | 103ms | 5260 KiB | ||||
17 | Wrong answer | 105ms | 5612 KiB | ||||
18 | Wrong answer | 2ms | 4276 KiB | ||||
19 | Wrong answer | 3ms | 4132 KiB | ||||
20 | Wrong answer | 2ms | 4128 KiB | ||||
21 | Wrong answer | 104ms | 5588 KiB | ||||
22 | Wrong answer | 105ms | 5532 KiB | ||||
23 | Wrong answer | 104ms | 5536 KiB | ||||
subtask5 | 0/29 | ||||||
24 | Wrong answer | 104ms | 5536 KiB | ||||
25 | Wrong answer | 104ms | 5792 KiB | ||||
26 | Wrong answer | 104ms | 5844 KiB | ||||
27 | Wrong answer | 104ms | 5740 KiB | ||||
28 | Wrong answer | 104ms | 6008 KiB | ||||
29 | Wrong answer | 104ms | 6104 KiB | ||||
30 | Wrong answer | 105ms | 6132 KiB | ||||
31 | Wrong answer | 103ms | 6080 KiB | ||||
32 | Wrong answer | 104ms | 6140 KiB | ||||
subtask6 | 0/10 | ||||||
33 | Wrong answer | 104ms | 6136 KiB | ||||
34 | Wrong answer | 108ms | 6332 KiB | ||||
35 | Wrong answer | 108ms | 6528 KiB | ||||
36 | Wrong answer | 107ms | 6500 KiB | ||||
37 | Wrong answer | 105ms | 6460 KiB | ||||
38 | Wrong answer | 107ms | 6456 KiB |