-
Notifications
You must be signed in to change notification settings - Fork 0
/
1049.js
29 lines (24 loc) · 889 Bytes
/
1049.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*
제일 싼 여섯 개 패키지 가격
제일 싼 낱개 패키지 가격
이거 두 개 구해서 계산하기
*/
const INPUT_FILE = process.platform === 'linux' ? '/dev/stdin' : './input';
const [[lineCount], ...prices] = require('fs')
.readFileSync(INPUT_FILE)
.toString()
.trim()
.split('\n')
.map((line) => line.split(' ').map(Number));
const { minPackagePrice, minSinglePrice } = prices.reduce(
({ minPackagePrice, minSinglePrice }, [packagePrice, singlePrice]) => ({
minPackagePrice: Math.min(packagePrice, minPackagePrice),
minSinglePrice: Math.min(singlePrice, minSinglePrice),
}),
{ minPackagePrice: Infinity, minSinglePrice: Infinity },
);
const packagePrice = Math.min(minPackagePrice, minSinglePrice * 6);
const sol =
Math.min(minPackagePrice, (lineCount % 6) * minSinglePrice) +
Math.floor(lineCount / 6) * packagePrice;
console.log(sol);