結果

問題 No.568 じゃんじゃん 落とす 委員会
ユーザー htensaihtensai
提出日時 2020-01-30 19:06:46
言語 Java21
(openjdk 21)
結果
AC  
実行時間 552 ms / 1,000 ms
コード長 2,991 bytes
コンパイル時間 1,756 ms
コンパイル使用メモリ 74,940 KB
実行使用メモリ 61,780 KB
最終ジャッジ日時 2023-10-14 08:40:13
合計ジャッジ時間 9,948 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 394 ms
59,956 KB
testcase_01 AC 373 ms
60,096 KB
testcase_02 AC 71 ms
52,036 KB
testcase_03 AC 75 ms
50,872 KB
testcase_04 AC 76 ms
51,052 KB
testcase_05 AC 61 ms
50,708 KB
testcase_06 AC 69 ms
51,704 KB
testcase_07 AC 70 ms
50,880 KB
testcase_08 AC 64 ms
50,888 KB
testcase_09 AC 71 ms
51,264 KB
testcase_10 AC 61 ms
50,636 KB
testcase_11 AC 75 ms
50,968 KB
testcase_12 AC 390 ms
60,316 KB
testcase_13 AC 421 ms
59,700 KB
testcase_14 AC 472 ms
60,532 KB
testcase_15 AC 426 ms
61,340 KB
testcase_16 AC 425 ms
60,044 KB
testcase_17 AC 367 ms
60,280 KB
testcase_18 AC 441 ms
59,960 KB
testcase_19 AC 552 ms
61,780 KB
testcase_20 AC 358 ms
60,768 KB
testcase_21 AC 432 ms
59,804 KB
testcase_22 AC 396 ms
59,972 KB
testcase_23 AC 58 ms
50,832 KB
testcase_24 AC 58 ms
50,736 KB
testcase_25 AC 60 ms
50,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;

public class Main {
    static int[] dp;
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] first = br.readLine().split(" ", 2);
        int n = Integer.parseInt(first[0]);
        int m = Integer.parseInt(first[1]);
        PriorityQueue<Person> aQueue = new PriorityQueue<Person>(new Comparator<Person>() {
            public int compare(Person p1, Person p2) {
                return p1.a - p2.a;
            }
        });
        PriorityQueue<Person> bQueue = new PriorityQueue<Person>(new Comparator<Person>() {
            public int compare(Person p1, Person p2) {
                return p2.b - p1.b;
            }
        });
        int comp3 = 0;
        int comp2 = 0;
        for (int i = 0; i < n; i++) {
            Person p = new Person(br.readLine());
            if (p.count >= 3) {
                comp3++;
                comp2++;
                continue;
            } else if (p.count >= 2) {
                comp3++;
                comp2++;
            } else if (p.count >= 1) {
                comp2++;
            }
            aQueue.add(p);
            bQueue.add(p);
        }
        int min = Integer.MAX_VALUE;
        while (true) {
            if (comp2 < m) {
                if (bQueue.size() == 0) {
                    break;
                }
                int tmp = bQueue.peek().b;
                while (bQueue.size() > 0 && tmp == bQueue.peek().b) {
                    Person p = bQueue.poll();
                    p.count++;
                    if (p.count == 2) {
                        comp3++;
                    } else if (p.count == 1) {
                        comp2++;
                    }
                }
            } else {
                min = Math.min(min, comp3);
                if (aQueue.size() == 0) {
                    break;
                }
                int tmp = aQueue.peek().a;
                while (aQueue.size() > 0 && tmp == aQueue.peek().a) {
                    Person p = aQueue.poll();
                    p.count--;
                    if (p.count == 1) {
                        comp3--;
                    } else if (p.count == 0) {
                        comp2--;
                    }
                }
            }
        }
        System.out.println(min);
    }
    
    static class Person {
        int a;
        int b;
        int count;
        
        public Person(int count, int a, int b) {
            this.a = a;
            this.b = b;
            this.count = count;
        }
        
        public Person(String a, String b, String c) {
            this(Integer.parseInt(a), Integer.parseInt(b), Integer.parseInt(c));
        }
        
        public Person(String[] arr) {
            this(arr[0], arr[1], arr[2]);
        }
        
        public Person(String s) {
            this(s.split(" ", 3));
        }
    }
}
0