-
-
Notifications
You must be signed in to change notification settings - Fork 109
/
MaximumElement.java
41 lines (39 loc) 路 1004 Bytes
/
MaximumElement.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
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int st[]=new int[100000];
int top1=0;
int top2=1;
int max[]=new int[100000];
max[top2]=0;
for(int j=0;j<n;j++){
int s=sc.nextInt();
if(s==1){
int num=sc.nextInt();
if(num>=max[top2-1]){
max[top2]=num;
top2++;
}
st[top1]=num;
top1++;
}
else if(s==2){
if(st[top1-1]==max[top2-1]){
max[top2-1]=0;
top2--;
}
st[top1-1]=0;
top1--;
}
else{
System.out.println(max[top2-1]);
}
}
}
}