From ea90baec0cbc1dd3854848d767ce6bd2a26b33d0 Mon Sep 17 00:00:00 2001 From: Ukj0ng <90972240+Ukj0ng@users.noreply.github.com> Date: Wed, 14 Jan 2026 15:32:43 +0900 Subject: [PATCH] =?UTF-8?q?[20260114]=20BOJ=20/=20P5=20/=20=EC=86=8C?= =?UTF-8?q?=EB=B0=A9=EC=84=9C=EC=9D=98=20=EA=B3=A0=EB=AF=BC=20/=20?= =?UTF-8?q?=ED=95=9C=EC=A2=85=EC=9A=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\354\235\230 \352\263\240\353\257\274.md" | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 "Ukj0ng/202601/14 BOJ P5 \354\206\214\353\260\251\354\204\234\354\235\230 \352\263\240\353\257\274.md" diff --git "a/Ukj0ng/202601/14 BOJ P5 \354\206\214\353\260\251\354\204\234\354\235\230 \352\263\240\353\257\274.md" "b/Ukj0ng/202601/14 BOJ P5 \354\206\214\353\260\251\354\204\234\354\235\230 \352\263\240\353\257\274.md" new file mode 100644 index 00000000..83f8d600 --- /dev/null +++ "b/Ukj0ng/202601/14 BOJ P5 \354\206\214\353\260\251\354\204\234\354\235\230 \352\263\240\353\257\274.md" @@ -0,0 +1,54 @@ +``` +import java.io.*; +import java.util.*; + +public class Main { + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + private static final int MOD = 40000; + private static PriorityQueue pq; + private static int N; + private static long t; + + public static void main(String[] args) throws IOException { + init(); + + while (!pq.isEmpty()) { + Task temp = pq.poll(); + t += temp.a*t+temp.b; + t %= MOD; + } + + bw.write(t + "\n"); + bw.flush(); + bw.close(); + br.close(); + } + + private static void init() throws IOException { + N = Integer.parseInt(br.readLine()); + + pq = new PriorityQueue<>((o1, o2) -> { + if (o1.a == 0 && o2.a == 0) return 0; + if (o1.a == 0) return 1; + if (o2.a == 0) return -1; + return Long.compare(o2.a*o1.b, o1.a*o2.b); + }); + + for (int i = 1; i <= N; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + pq.add(new Task(Long.parseLong(st.nextToken()), Long.parseLong(st.nextToken()))); + } + } + + static class Task { + long a; + long b; + + public Task(long a, long b) { + this.a = a; + this.b = b; + } + } +} +```