include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>>t;
while(t–){
int n,x;
cin>>n>>x;
vector v(n);
for(int i=0;i<n;i++){
cin>>v[i];
}
sort(v.begin(),v.end());
int part = -1;
for(int i=0;i<n;i++){
if(v[i]>=x){
part = i;
break;
}
}
if(part==-1){
cout<<0<<endl;
continue;
}
int extra = 0;
for(int i=part;i<n;i++){
extra += v[i] -x;
}
int count = n-part;
for(int i=part-1;i>=0;i--){
if(extra>= x-v[i]){
count++;
extra -= (x-v[i]);
}else{
break;
}
}
cout<<count<<endl;
}
}
this is my code I don’t think so it should’ve failed in any case.
one more thing is the problem statement states you can do only allocation from i to j, but i saw many approaches where people took all extra and sum them and subtracted the remaining part needed to make it equal to x which means we can just use sum of leftovers, but problem states you transfer i to j. I think there is some mistake