結果
問題 |
No.580 旅館の予約計画
|
ユーザー |
![]() |
提出日時 | 2020-02-17 16:26:48 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 124 ms / 2,000 ms |
コード長 | 2,051 bytes |
コンパイル時間 | 2,355 ms |
コンパイル使用メモリ | 79,736 KB |
実行使用メモリ | 52,640 KB |
最終ジャッジ日時 | 2024-10-06 14:59:51 |
合計ジャッジ時間 | 6,858 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 36 |
ソースコード
import java.util.*; import java.io.*; public class Main { public static void main (String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] first = br.readLine().split(" ", 2); int m = Integer.parseInt(first[0]); int n = Integer.parseInt(first[1]); ArrayList<Customer> list = new ArrayList<>(); for (int i = 0; i < n; i++) { list.add(new Customer(i, br.readLine())); } Collections.sort(list, new Comparator<Customer>() { public int compare(Customer c1, Customer c2) { if (c1.left == c2.left) { return c1.right - c2.right; } else { return c1.left - c2.left; } } }); TreeSet<Customer> stays = new TreeSet<>(); int count = 0; for (Customer c : list) { while (stays.size() > 0 && stays.first().right < c.left) { stays.pollFirst(); } stays.add(c); if (stays.size() > m) { count++; stays.pollLast(); } } System.out.println(n - count); } static class Customer implements Comparable<Customer> { int idx; int left; int right; public Customer(int idx, String line) { this.idx = idx; String[] args = line.split(" ", 4); left = Integer.parseInt(args[0]) * 24 * 60; String[] in = args[1].split(":", 2); left += Integer.parseInt(in[0]) * 60; left += Integer.parseInt(in[1]); right = Integer.parseInt(args[2]) * 24 * 60; String[] out = args[3].split(":", 2); right += Integer.parseInt(out[0]) * 60; right += Integer.parseInt(out[1]); } public int hashCode() { return idx; } public int compareTo(Customer another) { if (right == another.right) { return idx - another.idx; } else { return right - another.right; } } } }