Codeforces 1334B. Middle Class Solution

 Solution in C++:

///**********ALLAH IS ALMIGHTY************///

///AH Tonmoy

///Department of CSE,23rd batch

///Islamic University,Bangladesh  

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int n,x,i,c,cn,t;
  6. double s;
  7. cin>>t;
  8. while(t--)
  9. {
  10. cin>>n>>x;
  11. {
  12. cn=0;
  13. s=0;
  14. c=1;
  15. int a[n+9];
  16. for(i=0; i<n; i++)
  17. cin>>a[i];
  18. sort(a,a+n);
  19. for(i=n-1; i>=0; i--)
  20. {
  21. s+=a[i];
  22. if(s/(1.0*c)>=x)
  23. {
  24. cn++;
  25. c++;
  26. }
  27. else
  28. break;
  29. }
  30. }
  31. cout<<cn<<endl;
  32. }
  33. }

No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h &g...

Powered by Blogger.