Created
May 13, 2018 16:22
-
-
Save MrMeison/4c88330ca756fd2c736fb79fee91beb7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const sum = (arr, start, count) => arr.slice(start, start + count).reduce((res, val) => res + val, 0); | |
const solve = (n, a, b, c) => { | |
let i = 0; | |
let res = 0; | |
while(i < n) { | |
if (sum(a, i, 2) && b[i] + a[i + 1] > c[i]) { | |
res += c[i]; | |
i += 3; | |
} else if (sum(a, i, 1) > b[i]) { | |
res += b[i]; | |
i += 2; | |
} else { | |
res += a[i]; | |
i++; | |
} | |
} | |
return res; | |
}; | |
console.log(`${solve( | |
5, | |
[5, 2, 5, 20, 20], | |
[10, 10, 5, 20, 1], | |
[15, 15, 5, 1, 1] | |
)}`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment