fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define all(x) x.begin(), x.end()
  4. #define f1(i, n) for(int i=1;i<=n;++i)
  5. using namespace std;
  6.  
  7. const int maxn = 2e6 + 1;
  8.  
  9. int A[maxn];
  10. int n, k, max_length = 0, bin[100];
  11. vector<vector<int>> result;
  12.  
  13. void ql(int i) {
  14. if (i > n) {
  15. vector<int> v;
  16. v.clear();
  17. int sum = 0;
  18. for (int i = 1; i <= n; ++i) {
  19. if (bin[i] == 1) {
  20. v.push_back(A[i]);
  21. sum += A[i];
  22. }
  23. }
  24. if (sum <= k) {
  25. result.push_back(v);
  26. max_length = max(max_length, int(v.size()));
  27. }
  28. return;
  29. }
  30.  
  31. bin[i] = 1;
  32. ql(i + 1);
  33.  
  34. bin[i] = 0;
  35. ql(i + 1);
  36. }
  37.  
  38. int main() {
  39. ios::sync_with_stdio(false);
  40. cin.tie(nullptr);
  41.  
  42. cin >> n >> k;
  43. bool ok = false;
  44. for (int i = 1; i <= n; ++i) {
  45. cin >> A[i];
  46. if (A[i] <= k) ok = true;
  47. }
  48. if (!ok) {
  49. cout << 0;
  50. return 0;
  51. }
  52.  
  53. ql(1);
  54.  
  55. cout << max_length << endl;
  56. for (auto vec : result) {
  57. if (vec.size() == max_length) {
  58. for (auto x : vec) {
  59. cout << x << " ";
  60. }
  61. cout << endl;
  62. }
  63. }
  64. }
  65.  
  66.  
  67.  
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty