0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

paizaラーニング レベルアップ問題集 paizaの森練習問題コンテスト過去問題8 JavaScript 乗客人数 - その 2

Posted at

乗客人数 - その 2 (paizaランク C 相当)

解答例

const fs = require("fs");
const input = fs.readFileSync("/dev/stdin", "utf-8").trim();
const lines = input.split("\n");

const n = Number(lines[0]);
const a = lines[1].split(" ").map(Number);//降りる人
const b = lines[2].split(" ").map(Number);//乗る人

let max = 0;//最大乗車人数
let bus = 0;//バスの乗車人数
for (let i = 0; i < n; i++) { //i番目のバス停
  bus -= a[i];//降りる
  bus += b[i];//乗る
  max = Math.max(max, bus);//最大更新
}
console.log(max);
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?