fork(1) download
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. int n, m, k, a[111];
  6. unsigned long long f[10001];
  7.  
  8. int main() {
  9. int nTest;
  10. cin >> nTest;
  11. while (nTest--) {
  12. cin >> n >> m >> k;
  13. for (int i = 0; i < n; i++) cin >> a[i];
  14. memset(f, 0, sizeof(f));
  15. f[0] = 1;
  16. int vMax = 0;
  17. for (int i = 0; i < n; i++) {
  18. for (int j = vMax; j >= 0; j--) {
  19. if (j + a[i] <= m) {
  20. f[j + a[i]] += f[j];
  21. vMax = max(vMax, j + a[i]);
  22. if (f[j + a[i]] > k)
  23. f[j + a[i]] = k;
  24. }
  25. }
  26. }
  27. if (f[m] >= k)
  28. cout << "ENOUGH" << endl;
  29. else
  30. cout << f[m] << endl;
  31. }
  32. return 0;
  33. }
  34.  
Success #stdin #stdout 0s 3376KB
stdin
2
10 1000 7
100 200 300 400 500 600 700 800 900 1000
10 1000 30
100 200 300 400 500 600 700 800 900 1000
stdout
ENOUGH
10