結果

問題 No.2334 Distinct Cards
ユーザー Maeda
提出日時 2025-09-09 10:43:07
言語 Java
(openjdk 23)
結果
AC  
実行時間 510 ms / 2,000 ms
コード長 622 bytes
コンパイル時間 2,490 ms
コンパイル使用メモリ 76,936 KB
実行使用メモリ 50,788 KB
最終ジャッジ日時 2025-09-09 10:43:22
合計ジャッジ時間 10,648 ms
ジャッジサーバーID
(参考情報)
judge2 / judge
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
		int k = scan.nextInt();
        int[] cardList = new int[n];
        for(int i = 0 ; i < n ; i++){
        	int cardNo = scan.nextInt()-1;
        	cardList[cardNo]++;
        }
        Arrays.sort(cardList);
        int count = 0;
		for(int i = n-1;i >= 0 ; i--){
			if(cardList[i] == 0){
				continue;
			}
			if(k <= 0){
            	break;
            }
            k -= cardList[i];
            count++;
		}

        System.out.println(count);
    }
}
0