Last active
August 29, 2015 14:10
-
-
Save tommy351/73f8c34d839c67a0732f to your computer and use it in GitHub Desktop.
The solution to the question 3. https://paiza.jp/poh/enkoi
This file contains 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
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