프로그래밍/알고리즘 풀이
[node.js] 지능형 기차 2 ( 백준 2460번 )
카카수(kakasoo)
2021. 4. 6. 12:18
반응형
쉬는 시간이 주어져서 한 문제를 더 풀어보았다.
// 백준 2460번 지능형 기차를 풀었습니다.
const readline = require("readline");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
const input = [];
rl.on("line", (line) => {
input.push(line);
if (input.length === 10) {
main();
rl.close();
}
}).on("close", () => {
process.exit();
});
const main = () => {
const train = input.map((el) => el.split(" "));
let maxValue = 0;
let cur = 0;
train.forEach((el) => {
const wentOut = Number(el[0]);
const entered = Number(el[1]);
cur = cur - wentOut + entered;
if (maxValue < cur) {
maxValue = cur;
}
});
console.log(maxValue);
};
크게 어려울 거 없는 문제라 별로 설명할 게 없다.
반응형