Skip to content

Commit 5bcfdb3

Browse files
authored
[20251110] BOJ / G5 / 캠프 준비 / 이강현
1 parent 4572581 commit 5bcfdb3

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
```java
2+
import java.util.*;
3+
import java.io.*;
4+
5+
public class Main{
6+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
8+
static StringBuilder sb = new StringBuilder();
9+
static StringTokenizer st;
10+
static int N,L,R,X;
11+
static int[] problems;
12+
static int answer = 0;
13+
public static void main(String[] args) throws Exception {
14+
st = new StringTokenizer(br.readLine());
15+
N = Integer.parseInt(st.nextToken());
16+
L = Integer.parseInt(st.nextToken());
17+
R = Integer.parseInt(st.nextToken());
18+
X = Integer.parseInt(st.nextToken());
19+
20+
problems = new int[N];
21+
st = new StringTokenizer(br.readLine());
22+
for(int i=0; i<N;i++){
23+
problems[i] = Integer.parseInt(st.nextToken());
24+
}
25+
26+
select(0,0,Integer.MAX_VALUE,0,0);
27+
28+
bw.write(answer+"");
29+
bw.close();
30+
}
31+
public static void select(int sum, int max, int min, int depth, int count){
32+
if(depth == N){
33+
if(L <= sum && sum <= R && (max-min) >= X && count >= 2) answer++;
34+
return;
35+
}
36+
int newMax = Math.max(max,problems[depth]);
37+
int newMin = Math.min(min,problems[depth]);
38+
select(sum+problems[depth], newMax, newMin, depth+1, count+1);
39+
40+
select(sum, max, min, depth+1, count);
41+
}
42+
}
43+
```

0 commit comments

Comments
 (0)