-
Notifications
You must be signed in to change notification settings - Fork 0
/
AliensGuitarPlaying.java
69 lines (58 loc) · 1.72 KB
/
AliensGuitarPlaying.java
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
69
package Baekjoon.DataStructure;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
// 24-04-23 40min
// https://www.acmicpc.net/problem/2841
public class AliensGuitarPlaying {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int noteSize = Integer.parseInt(st.nextToken());
int pretSize = Integer.parseInt(st.nextToken());
PriorityQueue<Integer>[] pqs = new PriorityQueue[6 + 1];
for (int i = 0; i < 7; i++) {
pqs[i] = new PriorityQueue<>(Comparator.reverseOrder());
}
int result = 0;
for (int i = 0; i < noteSize; i++) {
st = new StringTokenizer(br.readLine());
int rowNum = Integer.parseInt(st.nextToken());
int pretNum = Integer.parseInt(st.nextToken());
PriorityQueue<Integer> curPQ = pqs[rowNum];
int curPeek = 0;
if (curPQ.isEmpty()) {
// 한 개도 없으면 넣기
curPQ.add(pretNum);
result++;
} else {
curPeek = curPQ.peek();
if (curPeek < pretNum) {
curPQ.add(pretNum);
result++;
} else if (curPeek > pretNum) {
while (!curPQ.isEmpty() && curPeek > pretNum) {
curPQ.poll();
result++;
if (!curPQ.isEmpty()) {
curPeek = curPQ.peek();
}
}
if (curPQ.isEmpty()) {
// 한 개도 없으면 넣기
curPQ.add(pretNum);
result++;
} else if (curPeek < pretNum) {
curPQ.add(pretNum);
result++;
}
}
// 현재와 같은 경우 아무 일도 일어나지 않음.
}
}
System.out.println(result);
}
}