fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. Scanner sc = new Scanner(System.in);
  13. int t = sc.nextInt();
  14. while(t-- > 0){
  15. int n = sc.nextInt();
  16. long c = sc.nextLong();
  17.  
  18. long b[] = new long[n+1];
  19. long sum=0;
  20. for(int i=1;i<=n;i++){
  21. b[i] = sc.nextLong();
  22. sum += b[i];
  23. }
  24. Arrays.sort(b,2,n+1);
  25. long ans =0;
  26. for(int do_it=1; do_it<=n-1; do_it++){
  27. long sum2 = 0;
  28. for(int j=2;j<=2+do_it-1;j++){
  29. sum2 += b[j];
  30. }
  31. long u1 = (sum-sum2)*sum2;
  32. sum2 =0;
  33. for(int j=n;j>=n-do_it+1;j--){
  34. sum2 += b[j];
  35. }
  36. u1 = Math.min(u1, (sum-sum2)*sum2);
  37. if(u1 <= c){
  38. ans = do_it;
  39. }
  40. }
  41.  
  42. System.out.print(n-ans);
  43. }
  44. }
  45. }
Success #stdin #stdout 0.12s 54576KB
stdin
4
3 1000000000000000000
2000000 4000000 5000000
4 150
100 1 1 1
6 1275
35 15 10 25 10 5
6 400
35 15 10 25 10 5
stdout
1346