Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solution(N, A, B) {
  2.     if (N - A < A) {
  3.         console.log("NO");
  4.         return false;
  5.     }
  6.     let result = recrsive(N, A, B, []);
  7.     result.sort(function (a, b) {
  8.         return a - b
  9.     });
  10.     console.log("YES");
  11.     console.log(result.join(" "));
  12. }
  13.  
  14. function recrsive(N, A, B, Arr) {
  15.     debugger;
  16.     if (N === 0)
  17.         return Arr;
  18.     else {
  19.         if (N < 0) {
  20.             Arr.slice(1, -1);
  21.             return recrsive(N + B, A, B - 1, Arr);
  22.         } else if (N - B >= A || N - B === 0) {
  23.             Arr.push(B);
  24.             return recrsive(N - B, A, B, Arr);
  25.         } else
  26.             return recrsive(N, A, B - 1, Arr);
  27.     }
  28.  
  29. }
  30.  
  31. function main() {
  32.     // write your code here.
  33.     // call functions `nextString`, `nextFloat` and `nextInt`
  34.     // to read the next token of input (ignoring whitespace)
  35.     // Alternatively, you can create your own input parser functions
  36.     // use console.log() to write to stdout
  37.     solution(nextInt(),nextInt(),nextInt());
  38.  
  39.     // var s = nextString();
  40.     // var c = nextChar();
  41.     // var f = nextFloat();
  42. }
  43.  
  44. // default parsers for JS.
  45. function nextInt() {
  46.     return parseInt(nextString());
  47. }
  48.  
  49. function nextFloat() {
  50.     return parseFloat(nextString());
  51. }
  52.  
  53. function nextString() {
  54.     var next_string = "";
  55.     clearWhitespaces();
  56.     while (input_cursor < input_stdin.length && !isWhitespace(input_stdin[input_cursor])) {
  57.         next_string += input_stdin[input_cursor];
  58.         input_cursor += 1;
  59.     }
  60.     return next_string;
  61. }
  62.  
  63. function nextChar() {
  64.     clearWhitespaces();
  65.     if (input_cursor < input_stdin.length) {
  66.         return input_stdin[input_cursor++];
  67.     } else {
  68.         return '\0';
  69.     }
  70. }
  71.  
  72. process.stdin.resume();
  73. process.stdin.setEncoding('ascii');
  74.  
  75. var input_stdin = "";
  76. var input_cursor = 0;
  77. process.stdin.on('data', function (data) {
  78.     input_stdin += data;
  79. });
  80. process.stdin.on('end', function () {
  81.     main();
  82. });
  83.  
  84. function isWhitespace(character) {
  85.     return ' \t\n\r\v'.indexOf(character) > -1;
  86. }
  87.  
  88. function clearWhitespaces() {
  89.     while (input_cursor < input_stdin.length && isWhitespace(input_stdin[input_cursor])) {
  90.         // ignore the next whitespace character
  91.         input_cursor += 1;
  92.     }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement