Skip to content

Instantly share code, notes, and snippets.

@orleika
Created February 2, 2015 09:41
Show Gist options
  • Save orleika/4c52ff7f9d5036244c0c to your computer and use it in GitHub Desktop.
Save orleika/4c52ff7f9d5036244c0c to your computer and use it in GitHub Desktop.
paizaオンラインハッカソン4 Lite
process.stdin.resume();
process.stdin.setEncoding('utf8');
var input_lines = '';
var parseInt10 = function (v) {
return parseInt(v, 10);
}
process.stdin.on('data', function (chunk) {
input_lines += chunk;
});
process.stdin.on('end', function () {
var lines = input_lines.trim().split("\n"),
p = lines[0].split(" ").map(parseInt10),
v = lines.slice(1, p[1] + 1).map(parseInt10),
ans, tmp, i;
ans = v.slice(0, p[0]).reduce(function (a, b) { return a + b; } );
for (i = 0, tmp = ans; i < p[1] - p[0]; i++) {
tmp += v[i+p[0]] - v[i];
if (ans < tmp) ans = tmp;
}
console.log(ans);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment