結果

問題 No.1380 Borderline
ユーザー ks2m
提出日時 2021-02-07 20:37:55
言語 Java
(openjdk 23)
結果
AC  
実行時間 131 ms / 2,000 ms
コード長 561 bytes
コンパイル時間 1,980 ms
コンパイル使用メモリ 76,380 KB
実行使用メモリ 42,120 KB
最終ジャッジ日時 2024-07-05 17:02:15
合計ジャッジ時間 8,029 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
import java.util.TreeMap;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		TreeMap<Integer, Integer> map = new TreeMap<>();
		for (int i = 0; i < n; i++) {
			int p = sc.nextInt();
			map.put(p, map.getOrDefault(p, 0) + 1);
		}
		sc.close();

		int ans = 0;
		while (!map.isEmpty()) {
			int v = map.pollLastEntry().getValue();
			if (ans + v > k) {
				break;
			}
			ans += v;
		}
		System.out.println(ans);
	}
}
0