What's wrong with this code? #include<bits/stdc++.h> using namespace std; int…
- User
What's wrong with this code?
#include<bits/stdc++.h> using namespace std; int a[100005],s[100005]; bool cmp(int y,int z){ return y>z; } int T; void solve(){ int n,x; cin>>n>>x; for(int i=1;i<=n;i++) cin>>a[i]; sort(a+1,a+n+1,cmp); s[1]=a[1]; for(int i=2;i<=n;i++) s[i]=s[i-1]+a[i]; if(a[1]<x){ cout<<0<<endl; return; } else { for(int i=n;i>=1;i--){ if(s[i]/i>=x){ cout<<i<<endl; break; } } } } int main(){ cin>>T; while(T--) solve(); return 0; }
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.