-
Notifications
You must be signed in to change notification settings - Fork 0
/
halcand.cpp
41 lines (39 loc) · 942 Bytes
/
halcand.cpp
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
#include<cstdio>
#include<algorithm>
using namespace std;
int main() {
int tests;
scanf("%d", &tests);
while(tests--) {
int n, k;
scanf("%d %d", &n, &k);
int* array = new int[n];
for(int i=0;i<n;++i) {
scanf("%d", array + i);
}
sort(array, array + n);
int index = 0;
bool cont = true;
int sum = 0;
while(cont && index < n) {
if(array[index] == 0) {
index++;
continue;
}
int val = array[index];
array[index] = 0;
for(int i=index+1;i - index < k;++i) {
if(i == n) {
cont = false;
break;
}
array[i] -= val;
}
if(cont) {
sum += val;
}
}
delete [] array;
printf("%d\n", sum);
}
}