240615 스카이라인 쉬운거

Jongleee·2024년 6월 15일
0

TIL

목록 보기
600/737
public static void main(String[] args) throws IOException {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	int n = Integer.parseInt(br.readLine());

	Deque<Integer> stack = new ArrayDeque<>();
	int count = 0;

	for (int i = 0; i < n; i++) {
		StringTokenizer st = new StringTokenizer(br.readLine());
		st.nextToken();
		int y = Integer.parseInt(st.nextToken());

		while (!stack.isEmpty() && stack.peek() > y) {
			stack.pop();
			count++;
		}

		if (stack.isEmpty() || stack.peek() != y) {
			stack.push(y);
		}
	}

	while (!stack.isEmpty()) {
		if (stack.pop() > 0) {
			count++;
		}
	}

	System.out.println(count);
	br.close();
}

출처:https://www.acmicpc.net/problem/1863

0개의 댓글