My issue
Explain my mistake in code
My code
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
int T;
cin>>T;
for(int i = 1; i <= T; i++) {
int N,X;
cin>>N>>X;
int A[N];
for(int j=0;j<N;j++) {
cin>>A[j];
}
sort(A,A+N,greater<int>());
int count = 0,bount = 0;
for(int j=0;j<N;j++) {
if(A[j] > X) {
count += A[j]-X;
}
}
for(int j=0;j<N;j++) {
if(A[j] >= X) {
bount++;
}
else if(A[j] < X) {
if(count >= X-A[j]) {
count = count - (X-A[j]);
bount++;
}
else {
break;
}
}
}
cout<<bount<<endl;
}
return 0;
}
Problem Link: Budget Allotment Practice Coding Problem