結果
問題 |
No.2334 Distinct Cards
|
ユーザー |
![]() |
提出日時 | 2025-03-20 18:53:15 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 95 ms / 2,000 ms |
コード長 | 787 bytes |
コンパイル時間 | 151 ms |
コンパイル使用メモリ | 82,600 KB |
実行使用メモリ | 108,568 KB |
最終ジャッジ日時 | 2025-03-20 18:54:25 |
合計ジャッジ時間 | 2,516 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 22 |
ソースコード
import sys from collections import Counter from itertools import accumulate def main(): n, k = map(int, sys.stdin.readline().split()) a = list(map(int, sys.stdin.readline().split())) freq = Counter(a) freqs = sorted(freq.values(), reverse=True) prefix = list(accumulate(freqs, initial=0)) # prefix[0]=0, prefix[1] = freqs[0], etc. low = 1 high = len(freqs) ans = high # Initialize with the maximum possible value while low <= high: mid = (low + high) // 2 if mid >= len(prefix): continue # This case shouldn't happen due to high being len(freqs) if prefix[mid] >= k: ans = mid high = mid - 1 else: low = mid + 1 print(ans) if __name__ == "__main__": main()