Skip to content

Commit a85d066

Browse files
committed
[20251029] BOJ / G5 / 캠프 준비 / 김민진
1 parent c72aa6b commit a85d066

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
```java
2+
import java.io.*;
3+
import java.util.Arrays;
4+
import java.util.StringTokenizer;
5+
6+
public class BJ_16938_캠프_준비 {
7+
8+
private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
9+
private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
10+
private static StringTokenizer st;
11+
12+
private static int N, L, R, X, ans;
13+
private static int[] questions, selected;
14+
15+
public static void main(String[] args) throws IOException {
16+
init();
17+
sol();
18+
}
19+
20+
private static void init() throws IOException {
21+
st = new StringTokenizer(br.readLine());
22+
23+
N = Integer.parseInt(st.nextToken());
24+
L = Integer.parseInt(st.nextToken());
25+
R = Integer.parseInt(st.nextToken());
26+
X = Integer.parseInt(st.nextToken());
27+
ans = 0;
28+
29+
st = new StringTokenizer(br.readLine());
30+
questions = new int[N];
31+
for (int i = 0; i < N; i++) {
32+
questions[i] = Integer.parseInt(st.nextToken());
33+
}
34+
Arrays.sort(questions);
35+
36+
selected = new int[N];
37+
}
38+
39+
private static void sol() throws IOException {
40+
dfs(0, 0);
41+
42+
bw.write(ans + "");
43+
bw.flush();
44+
bw.close();
45+
br.close();
46+
}
47+
48+
private static void dfs(int depth, int start) throws IOException {
49+
if (2 <= depth && depth <= N) {
50+
if (checkValid(depth)) {
51+
ans++;
52+
}
53+
}
54+
55+
if (depth == N) {
56+
return;
57+
}
58+
59+
for (int i = start; i < N; i++) {
60+
selected[depth] = i;
61+
dfs(depth + 1, i + 1);
62+
}
63+
}
64+
65+
private static boolean checkValid(int depth) throws IOException {
66+
int sum = 0;
67+
68+
for (int i = 0; i < depth; i++) {
69+
sum += questions[selected[i]];
70+
}
71+
72+
return L <= sum && sum <= R && questions[selected[depth - 1]] - questions[selected[0]] >= X;
73+
}
74+
75+
}
76+
```

0 commit comments

Comments
 (0)