fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <bits/stdc++.h>
  5.  
  6. using namespace std;
  7.  
  8. #define saleh \
  9.   ios_base::sync_with_stdio(false); \
  10.   cin.tie(nullptr);
  11. #define ll long long
  12.  
  13. int main()
  14. {
  15.  
  16. saleh;
  17.  
  18. int t;
  19. cin >> t;
  20. while (t--)
  21. {
  22. int n, sum;
  23. cin >> n >> sum;
  24. int ans = 0;
  25. vector<int> v(n);
  26. for (int i = 0; i < n; i++)
  27. cin >> v[i];
  28.  
  29. for (int mask = 0; mask < (1 << n); mask++)
  30. {
  31. int s = 0;
  32. for (int i = 0; i < n; i++)
  33. {
  34. if (mask & (1 << i))
  35. {
  36. s += v[i];
  37. }
  38. }
  39. int bits = __builtin_popcount(mask);
  40. if (s < sum)
  41. continue;
  42.  
  43. bool flag = 0;
  44. for (int i = 0; i < n; i++)
  45. {
  46. if (mask & (1 << i))
  47. {
  48. if (s - v[i] >= sum)
  49. flag = 1;
  50. }
  51. }
  52. if (!flag)
  53. ans = max(ans, bits);
  54. }
  55.  
  56. cout << ans << endl;
  57. }
  58. }
Success #stdin #stdout 0s 5272KB
stdin
Standard input is empty
stdout
Standard output is empty