From 41def7077773ed3b093497d22a2009c202755fdd Mon Sep 17 00:00:00 2001 From: Jonghwan Lee <123362165+0224LJH@users.noreply.github.com> Date: Sat, 13 Sep 2025 13:31:34 +0900 Subject: [PATCH] =?UTF-8?q?[20250913]=20BOJ=20/=20G2=20/=20=EC=BB=AC?= =?UTF-8?q?=EB=9F=AC=EB=B3=BC=20/=20=EC=9D=B4=EC=A2=85=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...J \354\273\254\353\237\254\353\263\274.md" | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 "0224LJH/202509/13 BOJ \354\273\254\353\237\254\353\263\274.md" diff --git "a/0224LJH/202509/13 BOJ \354\273\254\353\237\254\353\263\274.md" "b/0224LJH/202509/13 BOJ \354\273\254\353\237\254\353\263\274.md" new file mode 100644 index 00000000..cc3a5cd1 --- /dev/null +++ "b/0224LJH/202509/13 BOJ \354\273\254\353\237\254\353\263\274.md" @@ -0,0 +1,82 @@ +```java +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.*; + +public class Main { + + static StringBuilder sb = new StringBuilder(); + + static int ballCnt,sum; + static int[] ans,numSum; + static ArrayList[] balls; + + static class Ball { + int color; + int idx; + + public Ball (int color, int idx){ + this.color = color; + this.idx = idx; + } + + } + + + public static void main(String[] args) throws NumberFormatException, IOException { + init(); + process(); + print(); + } + + @SuppressWarnings("unchecked") + public static void init() throws NumberFormatException, IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + ballCnt = Integer.parseInt(br.readLine()); + ans = new int[ballCnt]; + numSum = new int[ballCnt+1]; // i번 색상 공의 크기 합 + balls = new ArrayList[2001]; + + for (int i = 0 ; i <= 2000; i++) balls[i] = new ArrayList<>(); + + for (int i = 0; i < ballCnt; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + int color = Integer.parseInt(st.nextToken()); + int size = Integer.parseInt(st.nextToken()); + Ball b = new Ball(color,i); + + balls[size].add(b); + } + + + + } + + public static void process() { + for (int i = 1; i <= 2000; i++) { + ArrayList tempBalls = balls[i]; + + for (Ball b: tempBalls) { + ans[b.idx] = sum - numSum[b.color]; + } + + for (Ball b: tempBalls) { + numSum[b.color] += i; + } + sum += tempBalls.size() * i; + + + } + + + for (int i = 0; i < ballCnt; i++) { + sb.append(ans[i]).append("\n"); + } + } + + public static void print() { + System.out.println(sb.toString()); + } +}```