fork download
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. int* solve(int* seed, int seedn, int seedsum, int n, int a, int b)
  6. {
  7. for (int i = b; i >= a; i--)
  8. {
  9. if (seedsum + i <= n)
  10. {
  11. int *seed1 = new int[seedn + 1];
  12. if (seedn > 0);
  13. memcpy(seed1, seed, sizeof(int) * (seedn));
  14. seed1[seedn] = i;
  15. if (seedsum + i == n) return seed1;
  16. int * p = solve(seed1, seedn + 1, seedsum + i, n, a, b);
  17. if (p != NULL) return p;
  18. }
  19. }
  20. return NULL;
  21. }
  22. int main()
  23. {
  24. int n, a, b;
  25. cin >> n >> a >> b;
  26. int *p = solve(NULL, 0, 0, n, a, b);
  27. if (p == NULL)
  28. cout << "NO" << endl;
  29. else
  30. {
  31. int sum = n;
  32. int i = 0;
  33. while (sum > 0)
  34. {
  35. i++;
  36. sum -= *p;
  37. p++;
  38. }
  39. p = p - i;
  40. cout << "YES" << endl;
  41. for (int j = i - 1; j >= 0; j--)
  42. cout << p[j] << " ";
  43. }
  44. return 0;
  45. }
Success #stdin #stdout 0s 4364KB
stdin
59 8 10
stdout
YES
9 10 10 10 10 10