Created
December 8, 2016 18:45
-
-
Save yamadayuki/ed86b14cc977f7f71e97dd63aa5de47f to your computer and use it in GitHub Desktop.
Maximum Profit
This file contains hidden or 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
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_D | |
// Test Case | |
// 6 | |
// 2 | |
// 3 | |
// 1 | |
// 3 | |
// 4 | |
// 3 | |
// => 3 | |
var input = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n').map(Number); | |
var n = input.shift(); | |
var minimum = input[0]; | |
var maximum = -Math.pow(10, 9) * 2; | |
for (var i = 1; i < input.length; i++) { | |
maximum = Math.max(maximum, input[i] - minimum); | |
minimum = Math.min(minimum, input[i]); | |
} | |
console.log(maximum); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment