From 398901e7f95027276f86435a01485141d2023492 Mon Sep 17 00:00:00 2001 From: Jinyeong Seol Date: Thu, 13 Feb 2025 17:29:16 +0900 Subject: [PATCH] =?UTF-8?q?[20250213]=20BOJ=20/=20=EA=B3=A8=EB=93=9C4=20/?= =?UTF-8?q?=20=ED=99=94=EC=9E=A5=EC=8B=A4=EC=9D=98=20=EA=B7=9C=EC=B9=99=20?= =?UTF-8?q?/=20=EC=84=A4=EC=A7=84=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\354\235\230 \352\267\234\354\271\231.md" | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 "Seol-JY/202502/13 BOJ G4 \355\231\224\354\236\245\354\213\244\354\235\230 \352\267\234\354\271\231.md" diff --git "a/Seol-JY/202502/13 BOJ G4 \355\231\224\354\236\245\354\213\244\354\235\230 \352\267\234\354\271\231.md" "b/Seol-JY/202502/13 BOJ G4 \355\231\224\354\236\245\354\213\244\354\235\230 \352\267\234\354\271\231.md" new file mode 100644 index 00000000..a0aa46e0 --- /dev/null +++ "b/Seol-JY/202502/13 BOJ G4 \355\231\224\354\236\245\354\213\244\354\235\230 \352\267\234\354\271\231.md" @@ -0,0 +1,88 @@ +```java +import java.io.*; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.List; +import java.util.PriorityQueue; +import java.util.Queue; +import java.util.StringTokenizer; +public class Main { + public static void main(String[] args) throws IOException { + Queue queue = new PriorityQueue<>(); + + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + int N = Integer.parseInt(st.nextToken()); + int M = Integer.parseInt(st.nextToken()); + int K = Integer.parseInt(st.nextToken()); + + + List> lists = new ArrayList<>(); + for (int i = 0; i < M; i++) { + lists.add(new ArrayDeque<>()); + } + + for (int i = 0; i < N; i++) { + lists.get(i%M).add(Person.create(br, K, i, i%M)); + } + + int answer = 0; + for (int i = 0; i < M; i++) { + if(!lists.get(i).isEmpty()) queue.add(lists.get(i).poll()); + } + while(true) { + Person person = queue.poll(); + if (person.getIsDeka()) { + System.out.println(answer); + break; + } + answer++; + + if(!lists.get(person.getLine()).isEmpty()) { + queue.add(lists.get(person.getLine()).poll()); + } + } + + + } + + static class Person implements Comparable { + private final int d; + private final int h; + private final boolean isDeka; + private final int line; + + private Person(int d, int h, boolean isDeka, int line) { + this.d = d; + this.h = h; + this.isDeka = isDeka; + this.line = line; + } + + public static Person create(BufferedReader br, int k, int index, int line) throws IOException { + StringTokenizer st = new StringTokenizer(br.readLine()); + return new Person(Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken()), index == k, line); + } + + public int getLine() { + return this.line; + } + + public boolean getIsDeka() { + return this.isDeka; + } + + @Override + public int compareTo(Person o) { + int compareD = o.d - this.d; + if (compareD != 0) return compareD; + + int compareH = o.h - this.h; + if (compareH != 0) return compareH; + + return this.line - o.line; + } + } +} + +```