Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions lkhyun/202511/10 BOJ G5 캠프 준비.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
```java
import java.util.*;
import java.io.*;

public class Main{
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
static StringBuilder sb = new StringBuilder();
static StringTokenizer st;
static int N,L,R,X;
static int[] problems;
static int answer = 0;
public static void main(String[] args) throws Exception {
st = new StringTokenizer(br.readLine());
N = Integer.parseInt(st.nextToken());
L = Integer.parseInt(st.nextToken());
R = Integer.parseInt(st.nextToken());
X = Integer.parseInt(st.nextToken());

problems = new int[N];
st = new StringTokenizer(br.readLine());
for(int i=0; i<N;i++){
problems[i] = Integer.parseInt(st.nextToken());
}

select(0,0,Integer.MAX_VALUE,0,0);

bw.write(answer+"");
bw.close();
}
public static void select(int sum, int max, int min, int depth, int count){
if(depth == N){
if(L <= sum && sum <= R && (max-min) >= X && count >= 2) answer++;
return;
}
int newMax = Math.max(max,problems[depth]);
int newMin = Math.min(min,problems[depth]);
select(sum+problems[depth], newMax, newMin, depth+1, count+1);

select(sum, max, min, depth+1, count);
}
}
```