-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathKSUM_2.cpp
More file actions
47 lines (32 loc) · 779 Bytes
/
KSUM_2.cpp
File metadata and controls
47 lines (32 loc) · 779 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <bits/stdc++.h>
using namespace std;
#define MAXN 100000
int n, k, a[MAXN];
void Solve() {
cin >> n >> k;
long long sum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
priority_queue <pair <long long, int> > pr;
for (int i = 0; i < n; i++) {
pr.push(make_pair(sum, n - 1));
sum -= a[i];
}
while (k--) {
pair <long long, int> cur = pr.top();
pr.pop();
cout << cur.first << " ";
if (cur.second) {
pr.push(make_pair(cur.first - a[cur.second], cur.second - 1));
}
}
}
int main(void) {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
Solve();
return 0;
}