Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function processData(input) {
- var lines = input.split('\n');
- for (var i=2; i<lines.length; i+=2) {
- var arr = lines[i].split(' ').map(function(x) { return parseInt(x); });
- if (arr.length > 1) {
- var sum = 0;
- // First, get the sum of the entire array.
- for (var j=0; j<arr.length; j++) {
- sum += arr[j];
- }
- // Now step through using each value as a test index for left and right sums.
- // We can add and subtract at each step to change the left and right sums accordingly.
- var sumLeft = 0;
- var sumRight = 0;
- for (var j=1; j<arr.length - 1; j++) {
- sumLeft += arr[j-1];
- sumRight = sum - sumLeft - arr[j];
- if (sumLeft === sumRight) {
- break;
- }
- }
- if (j < arr.length - 1) {
- console.log('YES');
- }
- else {
- console.log('NO');
- }
- }
- else {
- // Sum considered to be 0 for a single element array.
- console.log('YES');
- }
- }
- }
- process.stdin.resume();
- process.stdin.setEncoding("ascii");
- _input = "";
- process.stdin.on("data", function (input) {
- _input += input;
- });
- process.stdin.on("end", function () {
- processData(_input);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement