From 7e250ec0abb105e6ea209b98055c05c9a40ea412 Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Tue, 22 Jul 2025 16:54:56 +0900 Subject: [PATCH] =?UTF-8?q?[20250722]=20BOJ=20/=20G5=20/=20=EC=BA=A0?= =?UTF-8?q?=ED=94=84=20=EC=A4=80=EB=B9=84=20/=20=EA=B9=80=EC=88=98?= =?UTF-8?q?=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\355\224\204 \354\244\200\353\271\204.md" | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 "suyeun84/202507/22 BOJ G5 \354\272\240\355\224\204 \354\244\200\353\271\204.md" diff --git "a/suyeun84/202507/22 BOJ G5 \354\272\240\355\224\204 \354\244\200\353\271\204.md" "b/suyeun84/202507/22 BOJ G5 \354\272\240\355\224\204 \354\244\200\353\271\204.md" new file mode 100644 index 00000000..a3e7ac4b --- /dev/null +++ "b/suyeun84/202507/22 BOJ G5 \354\272\240\355\224\204 \354\244\200\353\271\204.md" @@ -0,0 +1,48 @@ +```java +import java.util.*; +import java.io.*; + +public class boj16938 { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static StringTokenizer st; + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} + static int nextInt() {return Integer.parseInt(st.nextToken());} + + static int N, L, R, X; + static int[] arr; + static int tmp_cnt,tmp_min,tmp_answer; + public static void main(String[] args) throws Exception { + nextLine(); + N = nextInt(); + L = nextInt(); + R = nextInt(); + X = nextInt(); + arr = new int[N]; + nextLine(); + for (int i = 0; i < N; i++) arr[i] = nextInt(); + Arrays.sort(arr); + + int answer = 0; + for(int i = 0; i < N-1; i++) { + tmp_cnt = N-i; + tmp_min = arr[i]; + tmp_answer = 0; + comb(i+1,1,1,arr[i],arr[i]); + answer += tmp_answer; + } + System.out.print(answer); + } + + static void comb(int idx, int cnt,int add_cnt,int max,int tot) { + if(cnt == tmp_cnt) { + if(add_cnt > 1 && (max-tmp_min >= X) && (tot >= L && tot <= R)) tmp_answer++; + return; + } + + for(int i = idx; i < N; i++) { + comb(i+1,cnt+1,add_cnt,max,tot); + comb(i+1,cnt+1,add_cnt+1,arr[i],tot+arr[i]); + } + } +} +```