fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. #define el << "\n"
  5.  
  6. void turbo(){
  7. ios::sync_with_stdio(false);
  8. cin.tie(nullptr);
  9. cout.tie(nullptr);
  10. }
  11.  
  12. void solve(){
  13. ll n,s;
  14. cin>>n>>s;
  15. ll a[100005];
  16. for(int i=0;i<n;i++){
  17. cin>>a[i];
  18. }
  19.  
  20. sort(a,a+n);
  21. ll sum = 0;
  22. int count =0;
  23. for(int i=0;i<n;i++){
  24. if(sum+a[i] <= s){
  25. sum += a[i];
  26. count++;
  27. }
  28. else{
  29. break;
  30. }
  31. }
  32. cout << count el;
  33. cout << "Eid Mubarak\n";
  34. }
  35.  
  36.  
  37. int main(){
  38.  
  39. turbo();
  40. solve();
  41.  
  42. return 0;
  43. }
Success #stdin #stdout 0.01s 5316KB
stdin
5 8
2 7 3 4 5
stdout
2
Eid Mubarak