Advertisement
Saleh127

Untitled

Apr 10th, 2020
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. long long a[200000],b,c,d,e,f,i,j,k,l;
  6. cin>>b;
  7. while(b--)
  8. {
  9. cin>>c>>d;
  10. f=0;
  11. e=0;
  12. k=0;
  13. l=0;
  14. for(i=0; i<c; i++)
  15. {
  16. cin>>a[i];
  17. if(a[i]>=d)
  18. e++;
  19. }
  20. if(e==0)
  21. {
  22. printf("0\n");
  23. continue;
  24. }
  25. sort(a,a+c,greater<int>());
  26. for(j=0; j<c; j++)
  27. {
  28. if(a[j]>=d)
  29. {
  30. f+=a[j]-d;
  31. a[j]=d;
  32. }
  33. else
  34. {
  35. k=d-a[j];
  36. if(f-k>=0)
  37. {
  38. a[j]=a[j]+k;
  39. f-=k;
  40. }
  41. else a[j]=a[j];
  42. }
  43. }
  44. for(j=0; j<c; j++)
  45. {
  46. if(a[j]>=d)
  47. {
  48. l++;
  49. }
  50. }
  51. cout<<l<<endl;
  52. }
  53. return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement