From 4235a021b221bc5cf1ecbca0667edd1eeacd42fc Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Mon, 20 Oct 2025 16:46:29 +0900 Subject: [PATCH] =?UTF-8?q?[20251020]=20BOJ=20/=20G2=20/=20=EC=BB=AC?= =?UTF-8?q?=EB=9F=AC=EB=B3=BC=20/=20=EA=B9=80=EC=88=98=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...2 \354\273\254\353\237\254\353\263\274.md" | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 "suyeun84/202510/20 BOJ G2 \354\273\254\353\237\254\353\263\274.md" diff --git "a/suyeun84/202510/20 BOJ G2 \354\273\254\353\237\254\353\263\274.md" "b/suyeun84/202510/20 BOJ G2 \354\273\254\353\237\254\353\263\274.md" new file mode 100644 index 00000000..9d9395a4 --- /dev/null +++ "b/suyeun84/202510/20 BOJ G2 \354\273\254\353\237\254\353\263\274.md" @@ -0,0 +1,47 @@ +```java +import java.io.*; +import java.util.*; + +public class boj10800 { + 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(); + Ball[] balls = new Ball[N]; + for (int i = 0; i < N; i++) { + nextLine(); + balls[i] = new Ball(nextInt(), nextInt(), i); + } + // 공 색깔 별로 + Arrays.sort(balls, (o1, o2) -> o1.s - o2.s); + int[] colors = new int[N+1]; + int[] answer = new int[N]; + int idx = 0, sum = 0; + for (int i = 0; i < N; i++) { + Ball curr = balls[i]; + while(balls[idx].s < curr.s) { + sum += balls[idx].s; + colors[balls[idx].c] += balls[idx].s; + idx++; + } + answer[curr.idx] = sum - colors[curr.c]; + } + for (int i = 0; i < N; i++) { + System.out.println(answer[i]); + } + } + + static class Ball { + int c, s, idx; + public Ball(int c, int s, int idx) { + this.c = c; + this.s = s; + this.idx = idx; + } + } +} +```