Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solution(N, A, B) {
- if (N - A < A) {
- console.log("NO");
- return false;
- }
- let result = recrsive(N, A, B, []);
- result.sort(function (a, b) {
- return a - b
- });
- console.log("YES");
- console.log(result.join(" "));
- }
- function recrsive(N, A, B, Arr) {
- debugger;
- if (N === 0)
- return Arr;
- else {
- if (N < 0) {
- Arr.slice(1, -1);
- return recrsive(N + B, A, B - 1, Arr);
- } else if (N - B >= A || N - B === 0) {
- Arr.push(B);
- return recrsive(N - B, A, B, Arr);
- } else
- return recrsive(N, A, B - 1, Arr);
- }
- }
- function main() {
- // write your code here.
- // call functions `nextString`, `nextFloat` and `nextInt`
- // to read the next token of input (ignoring whitespace)
- // Alternatively, you can create your own input parser functions
- // use console.log() to write to stdout
- solution(nextInt(),nextInt(),nextInt());
- // var s = nextString();
- // var c = nextChar();
- // var f = nextFloat();
- }
- // default parsers for JS.
- function nextInt() {
- return parseInt(nextString());
- }
- function nextFloat() {
- return parseFloat(nextString());
- }
- function nextString() {
- var next_string = "";
- clearWhitespaces();
- while (input_cursor < input_stdin.length && !isWhitespace(input_stdin[input_cursor])) {
- next_string += input_stdin[input_cursor];
- input_cursor += 1;
- }
- return next_string;
- }
- function nextChar() {
- clearWhitespaces();
- if (input_cursor < input_stdin.length) {
- return input_stdin[input_cursor++];
- } else {
- return '\0';
- }
- }
- process.stdin.resume();
- process.stdin.setEncoding('ascii');
- var input_stdin = "";
- var input_cursor = 0;
- process.stdin.on('data', function (data) {
- input_stdin += data;
- });
- process.stdin.on('end', function () {
- main();
- });
- function isWhitespace(character) {
- return ' \t\n\r\v'.indexOf(character) > -1;
- }
- function clearWhitespaces() {
- while (input_cursor < input_stdin.length && isWhitespace(input_stdin[input_cursor])) {
- // ignore the next whitespace character
- input_cursor += 1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement