1334B middle class

  1. #include <cstdio>
  2. #include <algorithm>
  3. #define LL long long
  4. using namespace std;
  5. int a[100010];
  6. LL sum;
  7. int cmp(int a,int b){
  8. return a>b;
  9. }
  10. int main(){
  11. int t,n,x,i,j,c=0;
  12. scanf("%d",&t);
  13. while(t--){
  14. c=0;
  15. scanf("%d%d",&n,&x);
  16. sum=0;
  17. for(i=1;i<=n;i++)scanf("%d",&a[i]);
  18. sort(a+1,a+1+n,cmp);
  19. j=0;
  20. for(i=1;i<=n;i++){
  21. if(a[i]>=x){ sum+=a[i]-x; c++;}
  22. else{j=i;break;}}
  23. if(j==0)
  24. {printf("%d\n",n);continue;}
  25. for(i=j;i<=n;i++)
  26. {
  27. if(sum>=x-a[i]){
  28. c++;
  29. sum-=x-a[i];
  30. }
  31. }
  32. printf("%d\n",c);
  33.  
  34. }
  35. return 0;
  36. }133

Comments

Popular posts from this blog

Codeforce Problem 1703A. YES or YES?

Aptitude test assistant programmer 2018

1041A. Heist solution