From fef914e8c23342081668cd3d1b0883b66d7623d5 Mon Sep 17 00:00:00 2001 From: oncsr Date: Wed, 12 Feb 2025 13:10:09 +0900 Subject: [PATCH] =?UTF-8?q?[20250212]=20BOJ=20/=20P5=20/=20=EB=B2=84?= =?UTF-8?q?=EC=8A=A4=20=EB=85=B8=EC=84=A0=20/=20=EA=B6=8C=ED=98=81?= =?UTF-8?q?=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\354\212\244 \353\205\270\354\204\240.md" | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 "khj20006/202502/12 BOJ P5 \353\262\204\354\212\244 \353\205\270\354\204\240.md" diff --git "a/khj20006/202502/12 BOJ P5 \353\262\204\354\212\244 \353\205\270\354\204\240.md" "b/khj20006/202502/12 BOJ P5 \353\262\204\354\212\244 \353\205\270\354\204\240.md" new file mode 100644 index 00000000..59ab6808 --- /dev/null +++ "b/khj20006/202502/12 BOJ P5 \353\262\204\354\212\244 \353\205\270\354\204\240.md" @@ -0,0 +1,71 @@ +```java + +import java.util.*; +import java.io.*; + +class Main { + + // IO field + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} + static int nextInt() {return Integer.parseInt(st.nextToken());} + static long nextLong() {return Long.parseLong(st.nextToken());} + static void bwEnd() throws Exception {bw.flush();bw.close();} + + // Additional field + static int N, M; + static List arr; + static boolean[] del; + + public static void main(String[] args) throws Exception { + + ready(); + solve(); + + bwEnd(); + } + + static void ready() throws Exception{ + + N = Integer.parseInt(br.readLine()); + M = Integer.parseInt(br.readLine()); + arr = new ArrayList<>(); + del = new boolean[M+1]; + for(int i=1;i<=M;i++) { + nextLine(); + int a = nextInt(), b = nextInt(); + if(a < b) { + arr.add(new int[] {a,b,i}); + arr.add(new int[] {N+a,N+b,i}); + } + else { + arr.add(new int[] {a,N+b,i}); + } + } + + } + + static void solve() throws Exception{ + + Collections.sort(arr, (a,b) -> { + if(a[0] == b[0]) return b[1]-a[1]; + return a[0]-b[0]; + }); + + int mx = 0; + for(int[] now : arr) { + int l = now[0], r = now[1], x = now[2]; + if(r<=mx) del[x] = true; + else mx = r; + } + for(int i=1;i<=M;i++) if(!del[i]) bw.write(i + " "); + + + } + +} + +```