File tree Expand file tree Collapse file tree 1 file changed +55
-0
lines changed
Expand file tree Collapse file tree 1 file changed +55
-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 Main {
6+
7+ static int cnt,ans;
8+ static int [] arr;
9+
10+ public static void main (String [] args ) throws Exception {
11+ init();
12+ process();
13+ print();
14+
15+ }
16+
17+ public static void init () throws IOException {
18+ BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
19+ cnt = Integer . parseInt(br. readLine());
20+ arr = new int [cnt];
21+ for (int i = 0 ; i < cnt; i++ ) {
22+ StringTokenizer st = new StringTokenizer (br. readLine());
23+ st. nextToken();
24+ arr[i] = Integer . parseInt(st. nextToken());
25+ }
26+ ans = 0 ;
27+ }
28+
29+ public static void process (){
30+ PriorityQueue<Integer > pq = new PriorityQueue<> (Collections . reverseOrder());
31+ for (int i = 0 ; i < cnt; i++ ) {
32+ int height = arr[i];
33+
34+ while (! pq. isEmpty() && pq. peek() > height) {
35+ pq. poll();
36+ ans++ ;
37+ }
38+
39+ if (height == 0 ) continue ;
40+
41+ if (pq. isEmpty() || pq. peek() != height) pq. add(height);
42+
43+
44+ }
45+
46+ ans += pq. size();
47+ }
48+
49+ public static void print (){
50+ System . out. println(ans);
51+ }
52+
53+
54+ }
55+ ```
You can’t perform that action at this time.
0 commit comments