Skip to content

Commit 69bc95f

Browse files
committed
[D4] Title: 장훈이의 높은 선반, Time: 102 ms, Memory: 27,648 KB -BaekjoonHub
1 parent 19ba94f commit 69bc95f

2 files changed

Lines changed: 66 additions & 2 deletions

File tree

SWEA/D4/1486. 장훈이의 높은 선반/README.md

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

55
### 성능 요약
66

7-
메모리: 9,042, 시간: 6,672, 코드길이: 73.79 Bytes
7+
메모리: 27,648 KB, 시간: 102 ms, 코드길이: 912 Bytes
88

99
### 제출 일자
1010

11-
2026년 07월 07일 23:12:27
11+
2026-09-10 11:20
1212

1313

1414

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import java.util.*;
2+
import java.io.FileInputStream;
3+
4+
5+
class Solution
6+
{
7+
public static int min;
8+
public static int N;
9+
public static int B;
10+
11+
public static int[] arr;
12+
13+
14+
public static void main(String args[]) throws Exception
15+
{
16+
17+
Scanner sc = new Scanner(System.in);
18+
int T;
19+
T=sc.nextInt();
20+
21+
for(int test_case = 1; test_case <= T; test_case++)
22+
{
23+
24+
N = sc.nextInt();
25+
B = sc.nextInt();
26+
min = Integer.MAX_VALUE;
27+
28+
int result = 0;
29+
30+
arr = new int[N];
31+
for(int i=0 ; i<N ; i++) {
32+
arr[i] = sc.nextInt();
33+
}
34+
35+
Arrays.sort(arr);
36+
37+
dfs(0,0);
38+
39+
result = min - B;
40+
41+
System.out.println("#" + test_case + " " + result);
42+
}
43+
44+
sc.close();
45+
}
46+
47+
public static void dfs(int idx, int sum){
48+
49+
50+
51+
if(sum >= min) return;
52+
53+
if(sum >= B) {
54+
min = Math.min(min, sum);
55+
return;
56+
}
57+
58+
if(idx == N) return;
59+
60+
dfs(idx+1, sum+arr[idx]);
61+
dfs(idx+1, sum);
62+
63+
}
64+
}

0 commit comments

Comments
 (0)