-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day_076.cpp
68 lines (59 loc) · 1.21 KB
/
Day_076.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
*Problem Statement: You are given N integers. In each step you can choose some K of the remaining numbers and
delete them, if the following condition holds: Let the K numbers you've chosen be a1, a2, a3, ..., aK in
sorted order. Then, for each i = K - 1, ai+1 must be greater than or equal to ai * C.You are asked to
calculate the maximum number of steps you can possibly make.
*Author: Kunal Kathpal (https://github.com/kunal-2002)
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ar array
const int mxN = 3e5;
const ll INF = 2e18;
int n, k, c;
ll a[mxN];
ll mul(ll x, ll y){
if((long double)x*y >= INF)
return INF;
return min(x*y,INF);
}
bool ok(int x){
vector<ll>v(a,a+x);
int ind = x;
for(int r=1;r<k;++r){
for(ll &i:v){
ll need = mul(i,c);
while(ind<n && a[ind]<need)
++ind;
if(ind==n)
return 0;
i = a[ind++];
}
}
return 1;
}
void solve(){
cin>>n>>k>>c;
for(int i=0;i<n;++i)
cin>>a[i];
sort(a,a+n);
int lb=0, rb=n/k;
while(lb<rb){
int mid = (lb+rb+1)/2;
if(ok(mid))
lb = mid;
else
rb = mid-1;
}
cout<<lb<<"\n";
}
int main(){
cout<<"Enter number of test cases:\t";
int T;
cin>>T;
while(T--){
solve();
}
return 0;
}