結果

問題 No.568 じゃんじゃん 落とす 委員会
ユーザー htensaihtensai
提出日時 2020-01-30 19:04:24
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,979 bytes
コンパイル時間 4,109 ms
コンパイル使用メモリ 74,716 KB
実行使用メモリ 61,836 KB
最終ジャッジ日時 2023-10-14 08:39:07
合計ジャッジ時間 12,594 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 376 ms
59,848 KB
testcase_01 AC 380 ms
60,352 KB
testcase_02 AC 74 ms
50,744 KB
testcase_03 AC 65 ms
50,732 KB
testcase_04 AC 73 ms
51,028 KB
testcase_05 AC 59 ms
50,876 KB
testcase_06 AC 74 ms
50,640 KB
testcase_07 AC 71 ms
50,672 KB
testcase_08 WA -
testcase_09 AC 62 ms
51,808 KB
testcase_10 AC 69 ms
51,060 KB
testcase_11 AC 71 ms
51,192 KB
testcase_12 AC 388 ms
60,144 KB
testcase_13 AC 476 ms
59,844 KB
testcase_14 AC 495 ms
60,852 KB
testcase_15 WA -
testcase_16 AC 411 ms
61,836 KB
testcase_17 AC 371 ms
60,172 KB
testcase_18 AC 409 ms
60,560 KB
testcase_19 AC 501 ms
61,384 KB
testcase_20 AC 384 ms
60,172 KB
testcase_21 AC 422 ms
60,236 KB
testcase_22 AC 365 ms
59,788 KB
testcase_23 AC 57 ms
51,020 KB
testcase_24 AC 58 ms
51,536 KB
testcase_25 AC 72 ms
50,720 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 = comp3;
        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