Skip to content

Commit 8e9bdb9

Browse files
committed
[D4] Title: 장훈이의 높은 선반, Time: 6,672, Memory: 9,042 -BaekjoonHub
1 parent 2484b2f commit 8e9bdb9

2 files changed

Lines changed: 77 additions & 0 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# [D4] 장훈이의 높은 선반 - 1486
2+
3+
[문제 링크](https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV2b7Yf6ABcBBASw)
4+
5+
### 성능 요약
6+
7+
메모리: 9,042, 시간: 6,672, 코드길이: 73.79 Bytes
8+
9+
### 제출 일자
10+
11+
2026년 07월 07일 23:12:27
12+
13+
14+
15+
> 출처: SW Expert Academy, https://swexpertacademy.com/main/code/problem/problemList.do
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import java.io.FileInputStream;
2+
import java.util.*;
3+
4+
class Solution
5+
{
6+
static int N, B;
7+
static int[] array;
8+
static int minDifference;
9+
10+
public static void main(String args[]) throws Exception
11+
{
12+
13+
Scanner sc = new Scanner(System.in);
14+
int T;
15+
T=sc.nextInt();
16+
17+
18+
for(int test_case = 1; test_case <= T; test_case++)
19+
{
20+
21+
22+
23+
N = sc.nextInt();
24+
B = sc.nextInt();
25+
26+
array = new int[N];
27+
int sum = 0;
28+
for(int i=0; i<N; i++){
29+
array[i] = sc.nextInt();
30+
sum += array[i];
31+
}
32+
33+
minDifference = Integer.MAX_VALUE;
34+
findMin(0,0);
35+
36+
System.out.println("#" + test_case + " " + minDifference);
37+
38+
39+
}
40+
}
41+
42+
static void findMin(int cnt, int sum){
43+
44+
if (sum - B >= minDifference) {
45+
return;
46+
}
47+
48+
if (cnt == N) {
49+
// 점원들의 합이 선반 높이 B 이상일 때만 최솟값 갱신
50+
if (sum >= B) {
51+
minDifference = Math.min(minDifference, sum - B);
52+
}
53+
return;
54+
}
55+
56+
findMin(cnt+1, sum+array[cnt]);
57+
58+
findMin(cnt+1, sum);
59+
60+
61+
}
62+
}

0 commit comments

Comments
 (0)