Skip to content

Commit 549f683

Browse files
committed
[Silver IV] Title: 동전 0, Time: 2020 ms, Memory: 10776 KB -BaekjoonHub
1 parent d240039 commit 549f683

2 files changed

Lines changed: 23 additions & 19 deletions

File tree

백준/Silver/11047. 동전 0/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
### 성능 요약
66

7-
메모리: 9620 KB, 시간: 128 ms
7+
메모리: 10776 KB, 시간: 2020 ms
88

99
### 분류
1010

1111
그리디 알고리즘
1212

1313
### 제출 일자
1414

15-
2023년 10월 12일 13:39:27
15+
2026년 3월 8일 21:42:07
1616

1717
### 문제 설명
1818

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
1-
/* /dev/stdin */
2-
let fs = require('fs');
3-
let input = fs.readFileSync('/dev/stdin').toString().split('\n');
1+
// /dev/stdin
2+
const fs = require("fs");
3+
let input = fs
4+
.readFileSync("/dev/stdin")
5+
.toString()
6+
.split("\n")
7+
.map((x) => x.replace("\r", ""));
48

5-
const count = parseInt(input[0].split(' ')[0]);
6-
let price = parseInt(input[0].split(' ')[1]);
7-
const arrCoins = [];
8-
let coinCount = 0;
9-
10-
for(let i = 1; i < count + 1; i++) {
11-
arrCoins.push(parseInt(input[i]));
9+
let [N, K] = input[0].split(" ").map(Number);
10+
const coins = [];
11+
for (let i = N; i > 0; i--) {
12+
coins.push(input[i]);
1213
}
14+
let answer = 0;
1315

14-
// arrCoins.sort((a,b) => b - a);
15-
16+
while (K > 0) {
17+
for (const coin of coins) {
18+
if (K >= coin) {
19+
K -= coin;
20+
break;
21+
}
22+
}
1623

17-
for(let i = arrCoins.length - 1; i >= 0; i--) {
18-
coinCount += parseInt(price / arrCoins[i]);
19-
price %= arrCoins[i];
20-
24+
answer++;
2125
}
2226

23-
console.log(coinCount);
27+
console.log(answer);

0 commit comments

Comments
 (0)