반응형
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
Stack<Long> building = new Stack<>();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
long sum = 0L;
building.push(Long.parseLong(br.readLine()));
for (int i=1; i<N; i++){
Long now = Long.parseLong(br.readLine());
if (now >= building.peek())
while (!building.isEmpty() && now >= building.peek())
building.pop();
sum += building.size();
building.push(now);
}
System.out.print(sum);
}
}
반응형
'Algorithm' 카테고리의 다른 글
백준 4889번 안정적인 문자열 [ Java ] (0) | 2020.12.28 |
---|---|
백준 5430번 AC [ Java ] (0) | 2020.12.27 |
백준 2493번 탑 [ Java ] (0) | 2020.12.26 |
백준 1158번 요세푸스 문제 [ Java ] (0) | 2020.12.25 |
백준 5397번 키로거 [ Java ] (0) | 2020.12.25 |