Skip to content

Commit d497d4c

Browse files
authored
Merge pull request #797 from AlgorithmWithGod/Ukj0ng
[20250902] BOJ / G5 / 캠프 준비 / 한종욱
2 parents 0bf8b22 + ef5cf46 commit d497d4c

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
```
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
8+
private static int[] arr, combination, temp;
9+
private static int N, L, R, X, answer;
10+
11+
public static void main(String[] args) throws IOException {
12+
init();
13+
for (int i = 2; i <= N; i++) {
14+
combination = new int[i];
15+
temp = new int[i];
16+
dfs(0, 0);
17+
}
18+
19+
bw.write(answer + "\n");
20+
bw.flush();
21+
bw.close();
22+
br.close();
23+
}
24+
25+
private static void init() throws IOException {
26+
StringTokenizer st = new StringTokenizer(br.readLine());
27+
N = Integer.parseInt(st.nextToken());
28+
L = Integer.parseInt(st.nextToken());
29+
R = Integer.parseInt(st.nextToken());
30+
X = Integer.parseInt(st.nextToken());
31+
answer = 0;
32+
33+
arr = new int[N];
34+
st = new StringTokenizer(br.readLine());
35+
36+
for (int i = 0; i < N; i++) {
37+
arr[i] = Integer.parseInt(st.nextToken());
38+
}
39+
40+
}
41+
42+
private static void dfs(int start, int index) {
43+
if (index == combination.length) {
44+
int[] clone = combination.clone();
45+
Arrays.sort(clone);
46+
int sum = Arrays.stream(clone).sum();
47+
if (sum < L) return;
48+
if (sum > R) return;
49+
if (clone[clone.length-1] - clone[0] < X) return;
50+
answer++;
51+
return;
52+
}
53+
54+
for (int i = start; i < N; i++) {
55+
combination[index] = arr[i];
56+
temp[index] = i;
57+
dfs(i+1, index+1);
58+
}
59+
}
60+
}
61+
62+
```

0 commit comments

Comments
 (0)