fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n, M;
  6. cin >> n >> M;
  7. int dem = 0;
  8.  
  9. int a[n];
  10. for (int i = 0; i < n; i++) {
  11. cin >> a[i];
  12. }
  13. sort(a, a + n);
  14. for (int i = 0; i < n; i++) {
  15. int s = 0;
  16. for (int j = i; j < n; j++) {
  17. s += a[j];
  18. if (s <= M) {
  19. dem++;
  20. }
  21. }
  22. }
  23. cout << dem;
  24.  
  25. return 0;
  26. }
Success #stdin #stdout 0s 5320KB
stdin
6 10 
1 2 7 10 15 5
stdout
8