const fs = require("fs");
const filePath = process.platform === "linux" ? "/dev/stdin" : "./input.txt";
const arr = fs.readFileSync(filePath).toString().trim().split("\n");
const n = Number(arr[0]);
const di = arr[1].split(" ").map(BigInt);
let price = arr[2].split(" ").map(BigInt);
price.pop(); // 마지막껀 안씀
let total = 0n; // BigInt
let nowPrice = price[0];
for (let i = 0; i < n - 1; i++) {
if (price[i] < nowPrice) {
nowPrice = price[i];
}
total += di[i] * nowPrice;
}
console.log(String(total));
그냥 Number
로 하니까 58점 밖에 받지 못했다. 문제 조건에서 각 거리와 리터당 가격이 최대 1,000,000,000 이하의 자연수라 Number
의 범위를 벗어나는 게 문제였다. BigInt
로 변경하니 100점이 나왔다.