-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbaekjoon_10800.java
More file actions
69 lines (51 loc) · 1.76 KB
/
baekjoon_10800.java
File metadata and controls
69 lines (51 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import java.util.*;
import java.io.*;
public class baekjoon_10800 {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
List<Player> arr = new ArrayList<>();
for(int i=1;i<=N;i++) {
StringTokenizer st = new StringTokenizer(br.readLine());
int color = Integer.parseInt(st.nextToken());
int cost = Integer.parseInt(st.nextToken());
arr.add(new Player(i, color, cost));
}
Collections.sort(arr, (o1, o2) -> {
if(o1.cost == o2.cost) {
return Integer.compare(o1.color, o2.color);
}
return Integer.compare(o1.cost, o2.cost);
});
int[] dp = new int[200001];
int ballIdx = 0, sum = 0;
for(int i=1;i<=N;i++) {
Player cur = arr.get(i - 1);
while(arr.get(ballIdx).cost < cur.cost) {
Player small = arr.get(ballIdx);
sum += small.cost;
dp[small.color] += small.cost;
ballIdx++;
}
cur.result = sum - dp[cur.color];
}
Collections.sort(arr, (o1, o2) -> Integer.compare(o1.idx, o2.idx));
for(Player p : arr) {
System.out.println(p.result);
}
}
public static class Player{
int color;
int cost;
int idx;
int result = 0;
public Player(int idx, int color, int cost) {
this.color = color;
this.cost = cost;
this.idx = idx;
}
public void setResult(int result) {
this.result = result;
}
}
}