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

+ Recent posts