Skip to content

Commit a9fc1e3

Browse files
authored
Merge pull request #1687 from AlgorithmWithGod/ksinji
[20251216] BOJ / G5 / 캠프 준비 / 강신지
2 parents b9d4e00 + 618069f commit a9fc1e3

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
static int n, l, r, y;
7+
static int[] a;
8+
static int ans = 0;
9+
10+
public static void main(String[] args) throws Exception {
11+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
12+
StringTokenizer st = new StringTokenizer(br.readLine());
13+
14+
n = Integer.parseInt(st.nextToken());
15+
l = Integer.parseInt(st.nextToken());
16+
r = Integer.parseInt(st.nextToken());
17+
y = Integer.parseInt(st.nextToken());
18+
19+
a = new int[n];
20+
st = new StringTokenizer(br.readLine());
21+
for (int i = 0; i < n; i++) a[i] = Integer.parseInt(st.nextToken());
22+
23+
dfs(0, 0, 0, 0, 0);
24+
System.out.println(ans);
25+
}
26+
27+
static void dfs(int idx, int cnt, int sum, int mn, int mx) {
28+
if (sum > r) return;
29+
30+
if (idx == n) {
31+
if (cnt >= 2 && sum >= l && sum <= r && (mx - mn) >= y) ans++;
32+
return;
33+
}
34+
35+
dfs(idx + 1, cnt, sum, mn, mx);
36+
37+
int v = a[idx];
38+
if (cnt == 0) {
39+
dfs(idx + 1, 1, sum + v, v, v);
40+
} else {
41+
dfs(idx + 1, cnt + 1, sum + v, Math.min(mn, v), Math.max(mx, v));
42+
}
43+
}
44+
}
45+
```

0 commit comments

Comments
 (0)