fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. const int Mod=1e9+7;
  5. const ll INF = 10000000000000;
  6. const int N = 1e6+7;
  7.  
  8. void solve() {
  9. ll n,k;
  10. cin >> n >> k;
  11. vector<ll> a(n);
  12. for(int i=0;i<n;i++) cin >> a[i];
  13. sort(a.begin(),a.end());
  14. ll prev=0;
  15. ll ans =k;
  16. for(int i=0;i<n && k>0;++i){
  17. k-=(a[i]-prev)*(n-i);
  18. prev=a[i];
  19. ans++;
  20. }
  21. cout << ans-1 << '\n';
  22. }
  23.  
  24. int main(){
  25. ios::sync_with_stdio(false);
  26. cin.tie(nullptr);
  27.  
  28. int t;
  29. cin >> t;
  30. while (t--) solve();
  31.  
  32. return 0;
  33. }
  34.  
Success #stdin #stdout 0.01s 5320KB
stdin
5
2 1
1 1
2 2
1 2
3 4
2 1 3
10 50
1 1 3 8 8 9 12 13 27 27
2 1000000000
1000000000 500000000
stdout
1
2
5
53
1000000000