-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdracarys.cpp
More file actions
56 lines (43 loc) · 849 Bytes
/
dracarys.cpp
File metadata and controls
56 lines (43 loc) · 849 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
48
49
50
51
52
53
54
55
56
#include<bits/stdc++.h>
using namespace std;
int getMinDragonFires(long *pos, int n, int r, long start) {
if(n <= 0) {
return 0;
}
long *eliminated = lower_bound(pos, pos + n, start + r);
for(int i = 0; i < n; i++) {
cout << pos[i] << " ";
}
cout << endl;
cout << eliminated - pos << endl;
if(*eliminated == start + r) {
eliminated++;
}
int newN = n - (eliminated - pos);
int last = 0;
int i = n-1;
while(pos[i] == pos[n-1]) {
last++;
i--;
}
newN -= last;
int ans = getMinDragonFires(eliminated, newN, r, start+r);
return 1 + ans;
}
int main () {
int q;
cin >> q;
while(q--) {
int n, r;
cin >> n >> r;
long *pos = new long[n];
for(int i = 0; i < n; i++) {
cin >> pos[i];
}
sort(pos, pos+n);
int ans = getMinDragonFires(pos, n, r, 0);
cout << ans << endl;
delete [] pos;
}
return 0;
}