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. int sum = 0;
  15. for (int i = 1; i <= n; i++){
  16. sum += a[i];
  17. if (sum > s) break;
  18. cnt ++;
  19. }
  20.  
  21. cout << cnt ;
  22. }
  23. int main(){
  24. ios_base::sync_with_stdio(0);
  25. cin.tie(0); cout.tie(0);
  26. solve();
  27. return 0;
  28. }
  29.  
Success #stdin #stdout 0s 5284KB
stdin
0 0
stdout
Standard output is empty