fork download
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. class Solution{
  5. static PrintWriter out;
  6. String INPUT = "";
  7. static long mod = (long)1e9+7L;
  8.  
  9. int n;
  10. long k, b;
  11. long[] a;
  12. long[] memo;
  13. public void solve(){
  14. n=ni(); //taking input, n is size of input array.
  15. k=nl(); b=nl();
  16. a=new long[n];
  17. memo=new long[n];
  18. Arrays.fill(memo, -1);
  19. for(int i=0; i<n; i++)a[i]=nl(); //taking input of array
  20. Arrays.sort(a);
  21.  
  22. if(k == 0){ //seprate case when k=0.
  23. int ct=0;
  24. for(int i=0; i<n; i++){
  25. if(a[i] >= b)ct+=1;
  26. }
  27. if(a[0] < b)ct+=1;
  28. out.println(ct);
  29. }
  30. else{ //when k>0.
  31. out.println(f(n-1));
  32. }
  33.  
  34. }
  35.  
  36. long f(int id){ //top-down dp approach.
  37. //out.println(id);
  38. if(id<0)return 0;
  39. if(memo[id] != -1){
  40. return memo[id];
  41. }
  42. if(id == 0){
  43. return memo[id] = 1;
  44. }
  45.  
  46. memo[id] = f(id-1);
  47.  
  48. long nxt = (a[id]-b)/Math.max(1L, k);
  49. int id1 = bs(0, id-1, nxt); //binary search for finding the index of nxt in the sorted array.
  50. memo[id] = Math.max(memo[id], 1+f(id1));
  51. return memo[id];
  52. }
  53.  
  54. int bs(int l, int r, long key){ //binary search function.
  55. while(l<r){
  56. int mid=l+(r-l+1)/2;
  57. if(a[mid] <= key)l=mid;
  58. else r=mid-1;
  59. }
  60. if(a[l] <= key){
  61. return l;
  62. }
  63. else{
  64. return -1;
  65. }
  66. }
  67.  
  68.  
  69.  
  70. //below is code for fast io.
  71.  
  72. void run(){
  73. is = new DataInputStream(System.in);
  74. out = new PrintWriter(System.out);
  75. int t=ni();while(t-->0)solve();
  76. out.flush();
  77. }
  78. public static void main(String[] args)throws Exception{new Solution().run();}
  79. long mod(long v, long m){if(v<0){long q=(Math.abs(v)+m-1L)/m;v=v+q*m;}return v%m;}
  80. long mod(long v){if(v<0){long q=(Math.abs(v)+mod-1L)/mod;v=v+q*mod;}return v%mod;}
  81. //Fast I/O code is copied from uwi code.
  82. private byte[] inbuf = new byte[1024];
  83. public int lenbuf = 0, ptrbuf = 0;
  84. private int readByte(){
  85. if(lenbuf == -1)throw new InputMismatchException();
  86. if(ptrbuf >= lenbuf){
  87. ptrbuf = 0;
  88. try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
  89. if(lenbuf <= 0)return -1;
  90. }
  91. return inbuf[ptrbuf++];
  92. }
  93. private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
  94. private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
  95. private double nd() { return Double.parseDouble(ns()); }
  96. private char nc() { return (char)skip(); }
  97. private String ns(){
  98. int b = skip();
  99. StringBuilder sb = new StringBuilder();
  100. while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
  101. sb.appendCodePoint(b);
  102. b = readByte();
  103. }
  104. return sb.toString();
  105. }
  106. private char[] ns(int n){
  107. char[] buf = new char[n];
  108. int b = skip(), p = 0;
  109. while(p < n && !(isSpaceChar(b))){
  110. buf[p++] = (char)b;
  111. b = readByte();
  112. }
  113. return n == p ? buf : Arrays.copyOf(buf, p);
  114. }
  115. private char[][] nm(int n, int m){
  116. char[][] map = new char[n][];
  117. for(int i = 0;i < n;i++)map[i] = ns(m);
  118. return map;
  119. }
  120. private int[] na(int n){
  121. int[] a = new int[n];
  122. for(int i = 0;i < n;i++)a[i] = ni();
  123. return a;
  124. }
  125. private int ni(){
  126. int num = 0, b;
  127. boolean minus = false;
  128. while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
  129. if(b == '-'){
  130. minus = true;
  131. b = readByte();
  132. }
  133. while(true){
  134. if(b >= '0' && b <= '9'){
  135. num = num * 10 + (b - '0');
  136. }else{
  137. return minus ? -num : num;
  138. }
  139. b = readByte();
  140. }
  141. }
  142. private long nl(){
  143. long num = 0;
  144. int b;
  145. boolean minus = false;
  146. while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
  147. if(b == '-'){
  148. minus = true;
  149. b = readByte();
  150. }
  151. while(true){
  152. if(b >= '0' && b <= '9'){
  153. num = num * 10 + (b - '0');
  154. }else{
  155. return minus ? -num : num;
  156. }
  157. b = readByte();
  158. }
  159. }
  160. static int i(long x){return (int)Math.round(x);}
  161. static class Pair implements Comparable<Pair>{
  162. long fs,sc;
  163. Pair(long a,long b){
  164. fs=a;sc=b;
  165. }
  166. public int compareTo(Pair p){
  167. if(this.fs>p.fs)return 1;
  168. else if(this.fs<p.fs)return -1;
  169. else{
  170. return i(this.sc-p.sc);
  171. }
  172. //return i(this.sc-p.sc);
  173. }
  174. public String toString(){
  175. return "("+fs+","+sc+")";
  176. }
  177. }
  178.  
  179. }
  180.  
  181.  
Success #stdin #stdout 0.1s 27984KB
stdin
Standard input is empty
stdout
Standard output is empty