Skip to content

Instantly share code, notes, and snippets.

@tommy351
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommy351/73f8c34d839c67a0732f to your computer and use it in GitHub Desktop.
Save tommy351/73f8c34d839c67a0732f to your computer and use it in GitHub Desktop.
The solution to the question 3. https://paiza.jp/poh/enkoi
var input = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
input += chunk;
});
process.stdin.on('end', function() {
var lines = input.split('\n');
var meta = lines.shift().split(' ');
var T = meta[0] | 0;
var N = meta[1] | 0;
var M = 0;
var sum = 0;
var max = Number.MIN_VALUE;
for (var i = 0; i < N; i++) {
M = lines[i] | 0;
sum += M;
if (i >= T) {
sum -= lines[i - T] | 0;
}
if (sum > max) max = sum;
}
console.log(max);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment