Untitled

 avatar
unknown
javascript
2 years ago
698 B
3
Indexable

let input = ["5 0", "1 1 1 1 0 1 1 1 1 1"];

let print = this.print || console.log;
let gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);

let sizeAndJumps = gets().split(" ");
let size = Number(sizeAndJumps[0]);
let jumps = Number(sizeAndJumps[1]);
let path = gets().split(" ").map(Number);
let growthBalance = 0;

for (i = 0; i < path.length; i++) {
  if (jumps > 0 && path[i] === -1) {
    jumps--;
  } else if (jumps > 0 && size > 0 && path[i] !== -1) {
    size += path[i];
    path[i] = 0;
  } else if (jumps === 0 && size > 0) {
    size += path[i];
    path[i] = 0;
  } else if (size === 0) {
    growthBalance += path[i];
  }
}

console.log(`${size} ${growthBalance}`);
Editor is loading...