https://www.acmicpc.net/problem/13305
13305번: 주유소
표준 입력으로 다음 정보가 주어진다. 첫 번째 줄에는 도시의 개수를 나타내는 정수 N(2 ≤ N ≤ 100,000)이 주어진다. 다음 줄에는 인접한 두 도시를 연결하는 도로의 길이가 제일 왼쪽 도로부터 N-1
www.acmicpc.net
const fs = require('fs');
const input = fs.readFileSync('/dev/stdin').toString().split("\n");
const N = input[0];
const km = input[1].split(" ").map( i => BigInt(i));
const cost = input[2].split(" ").map( i => BigInt(i));
let i = 0;
let current = cost[i];
let total = 0n;
while(true) {
if(current > cost[i]) {
current = cost[i];
}
total += current * km[i];
i+=1;
if(i === km.length) {
break;
}
}
console.log(String(total));
값이 크기 때문에 BigInt 를 쓰지 않으면 통과 하지 못함.
728x90
'Algorithm&CodingTest > Baekjoon' 카테고리의 다른 글
[ Baekjoon ] [1049] 그리디 실버3 - 기타줄 (0) | 2023.03.13 |
---|---|
[ Baekjoon ] [2607] 실버 3 - 비슷한 단어 (1) | 2023.03.12 |
[Baekjoon] [10814] 나이순 정렬 (0) | 2023.02.24 |
[Baekjoon] [2839] 설탕 배달 (0) | 2023.02.24 |
[Baekjoon] [1978] 실버4 - 소수찾기 (0) | 2023.02.24 |