Skip to content

Instantly share code, notes, and snippets.

@saschanaz
Last active December 5, 2015 18:42
Show Gist options
  • Select an option

  • Save saschanaz/762f2ef07a0a9f5c070b to your computer and use it in GitHub Desktop.

Select an option

Save saschanaz/762f2ef07a0a9f5c070b to your computer and use it in GitHub Desktop.
paiza
"use strict";
process.stdin.resume();
process.stdin.setEncoding('utf8');
// 自分の得意な言語で
// Let's チャレンジ!!
process.stdin.on('data', function (chunk) {
let items = chunk.split('\n');
let conditions = items[0].split(' ');
let rangeLength = parseInt(conditions[0]);
let attackLength = parseInt(conditions[1]);
let loopLength = attackLength - rangeLength + 1;
let lastAttack = 0;
for (let i = 1; i <= rangeLength; i++) {
lastAttack += (+items[i]);
}
let maxAttack = lastAttack;
for (let i = 1; i < loopLength; i++) {
lastAttack = lastAttack - parseInt(items[i]) + parseInt(items[i + rangeLength]);
if (lastAttack > maxAttack) {
maxAttack = lastAttack;
}
}
console.log(maxAttack);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment