fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int maxn=1e6+14;
  4. int a[maxn];
  5. void solve(){
  6. int n, s;
  7. cin >> n >> s;
  8. for (int i = 1; i <= n; i++){
  9. cin >> a[i];
  10. }
  11.  
  12. sort(a + 1, a + 1 + n);
  13. int cnt = 0;
  14. for (int i = 1; i <= n; i++){
  15. if (s < a[i]) break;
  16. s += a[i];
  17. cnt++;
  18. }
  19.  
  20. cout << cnt ;
  21. }
  22. int main(){
  23. ios_base::sync_with_stdio(0);
  24. cin.tie(0); cout.tie(0);
  25. solve();
  26. return 0;
  27. }
  28.  
Success #stdin #stdout 0.01s 5288KB
stdin
0 0
stdout
Standard output is empty