From 349e9b04ab822653d6b867c5e42ca36c38bb545e Mon Sep 17 00:00:00 2001 From: lkhyun <102892446+lkhyun@users.noreply.github.com> Date: Wed, 19 Feb 2025 18:57:52 +0900 Subject: [PATCH] =?UTF-8?q?[20250219]=20BOJ=20/=20=EA=B3=A8=EB=93=9C4=20/?= =?UTF-8?q?=20=EC=82=AC=EB=83=A5=EA=BE=BC=20/=20=EC=9D=B4=EA=B0=95?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4 \354\202\254\353\203\245\352\276\274.md" | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 "lkhyun/202502/19 BOJ \352\263\250\353\223\2344 \354\202\254\353\203\245\352\276\274.md" diff --git "a/lkhyun/202502/19 BOJ \352\263\250\353\223\2344 \354\202\254\353\203\245\352\276\274.md" "b/lkhyun/202502/19 BOJ \352\263\250\353\223\2344 \354\202\254\353\203\245\352\276\274.md" new file mode 100644 index 00000000..f55a259b --- /dev/null +++ "b/lkhyun/202502/19 BOJ \352\263\250\353\223\2344 \354\202\254\353\203\245\352\276\274.md" @@ -0,0 +1,67 @@ +```java +import java.util.*; +import java.io.*; + +public class Main { + public static void main(String[] args) throws Exception{ + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + StringTokenizer st = new StringTokenizer(br.readLine()); + int M = Integer.parseInt(st.nextToken()); + int N = Integer.parseInt(st.nextToken()); + int L = Integer.parseInt(st.nextToken()); + int[] Ms = new int[M]; + st = new StringTokenizer(br.readLine()); + for (int i = 0; i < M; i++) { + Ms[i] = Integer.parseInt(st.nextToken()); + } + List Ns = new ArrayList<>(N); + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + int x = Integer.parseInt(st.nextToken()); + int y = Integer.parseInt(st.nextToken()); + Ns.add(new int[]{x,y}); + } + + Arrays.sort(Ms); + + int count=0; + for (int[] i:Ns) { + int state = Arrays.binarySearch(Ms, i[0]); + if(state>=0){ + if(i[1]<=L){ + count++; + } + + }else{ + int temp = -(state+1); + int lefttemp = temp-1; + int righttemp = temp; + if(lefttemp<0){ + if((long)Ms[righttemp] - i[0] + i[1] <= (long)L){ + count++; + } + }else if(righttemp==Ms.length){ + if((long)i[0]-Ms[lefttemp] + i[1] <= (long)L){ + count++; + } + + }else{ + if((long)Ms[righttemp]-i[0]>(long)i[0]-Ms[lefttemp]){ + if((long)i[0]-Ms[lefttemp] + i[1] <= (long)L){ + count++; + } + }else{ + if((long)Ms[righttemp] - i[0] + i[1] <= (long)L){ + count++; + } + } + } + } + } + bw.write(String.valueOf(count)); + bw.flush(); + } +} + +```