Help me with problem 3

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

let test case be
1 2 6 as array and k= 3
let transfer all exceed value to index 1 from index 2 array become 1 5 3
Now, let transfer all exceed value to index 0 from index 1 array become 3 3 3
ans=3
if you think carefully you can take extra and solve this

ok, i got it but where my code is failing then
my approach is to put partition to divide the numbers on the left all the number which are smaller than x and on right all the number greater than or equal to x and calculate extra and after using the extra to calculate the ans

i think you are failing for overflow cases
take long long for extra

like n=1e5
and k=1;
array is 1e5 for all 0<=i<n

thanks, for the help. it didn’t click me at the time of contest

welcome just like the reply