본문 바로가기
코딩 문제 풀이/백준

[백준] 자바 문제 풀이 1374 : 골드5

by 코딩하는 랄로 2023. 9. 19.
728x90
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.PriorityQueue;

public class Main {
	public static class Lecture implements Comparable<Lecture> {
		long start;
		long end;

		public Lecture(int start, int end) {
			this.start = start;
			this.end = end;
		}

		@Override
		public int compareTo(Lecture lec) {
			return lec.start < start ? 1 : (lec.start > start ? -1 : 0);
		}
	}

	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		PriorityQueue<Lecture> pq = new PriorityQueue<>();

		for (int i = 0; i < n; i++) {
			String[] s = br.readLine().split(" ");
			pq.add(new Lecture(Integer.parseInt(s[1]), Integer.parseInt(s[2])));
		}

		PriorityQueue<Long> room = new PriorityQueue<>();
		while (!pq.isEmpty()) {
			Lecture lec = pq.poll();
			if (room.isEmpty()) {
				room.add(lec.end);
			} else {
				long r = room.poll();
				if (lec.start < r)
					room.add(r);
				room.add(lec.end);
			}
		}
		System.out.println(room.size());
	}

}
728x90