From 78b8b26ad1d3d726189676e3b3be369cfd3374eb Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Fri, 17 Oct 2025 18:38:48 +0900 Subject: [PATCH] =?UTF-8?q?[20251017]=20BOJ=20/=20G2=20/=20=EA=B5=AC?= =?UTF-8?q?=EA=B0=84=20=EC=9E=90=EB=A5=B4=EA=B8=B0=20/=20=EA=B9=80?= =?UTF-8?q?=EC=88=98=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4 \354\236\220\353\245\264\352\270\260.md" | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 "suyeun84/202510/17 BOJ G2 \352\265\254\352\260\204 \354\236\220\353\245\264\352\270\260.md" diff --git "a/suyeun84/202510/17 BOJ G2 \352\265\254\352\260\204 \354\236\220\353\245\264\352\270\260.md" "b/suyeun84/202510/17 BOJ G2 \352\265\254\352\260\204 \354\236\220\353\245\264\352\270\260.md" new file mode 100644 index 00000000..19c87873 --- /dev/null +++ "b/suyeun84/202510/17 BOJ G2 \352\265\254\352\260\204 \354\236\220\353\245\264\352\270\260.md" @@ -0,0 +1,53 @@ +```java +package boj; + +import java.io.*; +import java.util.*; + +public class boj2283 { + 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()); } + + public static void main(String[] args) throws Exception { + nextLine(); + int N = nextInt(); + int K = nextInt(); + int start= 1000001; + int end = 0; + int[] num = new int[1000001]; + // 누적합 생성 + for (int i = 0; i < N; i++) { + nextLine(); + int a = nextInt(); + int b = nextInt(); + num[a]++; + num[b]--; + start = Math.min(start, a); + end = Math.max(end, b); + } + for (int i = start+1; i <= end; i++) { + num[i] += num[i-1]; + } + + // 투 포인터 + int sum = 0; + int s = 0; + int e = start; + while (e <= end) { + if (sum < K) { + sum += num[e]; + e++; + } else if (sum == K) { + System.out.println(s+" "+e); + return; + } else { + sum -= num[s]; + s++; + } + } + System.out.println(0+" "+0); + } +} +```