File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed
Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.io.* ;
3+ import java.util.* ;
4+
5+ public class boj10800 {
6+ static BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
7+ static StringTokenizer st;
8+ static void nextLine () throws Exception { st = new StringTokenizer (br .readLine ()); }
9+ static int nextInt() { return Integer . parseInt(st. nextToken()); }
10+
11+ public static void main(String [] args) throws Exception {
12+ nextLine();
13+ int N = nextInt();
14+ Ball [] balls = new Ball [N ];
15+ for (int i = 0 ; i < N ; i++ ) {
16+ nextLine();
17+ balls[i] = new Ball (nextInt(), nextInt(), i);
18+ }
19+ // 공 색깔 별로
20+ Arrays . sort(balls, (o1, o2) - > o1. s - o2. s);
21+ int [] colors = new int [N + 1 ];
22+ int [] answer = new int [N ];
23+ int idx = 0 , sum = 0 ;
24+ for (int i = 0 ; i < N ; i++ ) {
25+ Ball curr = balls[i];
26+ while (balls[idx]. s < curr. s) {
27+ sum += balls[idx]. s;
28+ colors[balls[idx]. c] += balls[idx]. s;
29+ idx++ ;
30+ }
31+ answer[curr. idx] = sum - colors[curr. c];
32+ }
33+ for (int i = 0 ; i < N ; i++ ) {
34+ System . out. println(answer[i]);
35+ }
36+ }
37+
38+ static class Ball {
39+ int c, s, idx;
40+ public Ball (int c , int s , int idx ) {
41+ this . c = c;
42+ this . s = s;
43+ this . idx = idx;
44+ }
45+ }
46+ }
47+ ```
You can’t perform that action at this time.
0 commit comments