#include #define All(x) x.begin(),x.end() #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); using namespace std; using ll=long long; void solve(){ int n; cin>>n; vector a(n); for(auto &x:a) cin>>x; sort(All(a)); if(n==1) return cout< bool { int bg=0; unordered_map mp; for(int i=a.size()-1;i>=0;--i) if(a[i]0;--i){ if(mp[i]>=need) mp[i]-=need; else{ int tmp=need-mp[i]; mp[i]=0; need+=tmp; } mp[0]+=mp[i]; } return need<=mp[0]; }; int L=1,R=n; while(L>1; if(check(mid)) L=mid; else R=mid-1; } cout<>T; while(T--){ solve(); } }