-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB2493.java
More file actions
35 lines (27 loc) · 982 Bytes
/
B2493.java
File metadata and controls
35 lines (27 loc) · 982 Bytes
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
package Practice;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Stack;
import java.util.StringTokenizer;
public class B2493 { //ž
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
Stack<int[]> S = new Stack<>();
StringTokenizer st = new StringTokenizer(br.readLine());
for(int i = 1; i <= N; i++) {
int top = Integer.parseInt(st.nextToken());
while(!S.isEmpty()) {
if(S.peek()[1] >= top) {
System.out.print(S.peek()[0] + " ");
break;
}
S.pop();
}
if(S.isEmpty()) {
System.out.print("0 ");
}
S.push(new int[] {i, top});
}
}
}