結果
問題 | No.2334 Distinct Cards |
ユーザー |
![]() |
提出日時 | 2025-03-20 21:20:33 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 88 ms / 2,000 ms |
コード長 | 787 bytes |
コンパイル時間 | 164 ms |
コンパイル使用メモリ | 82,112 KB |
実行使用メモリ | 109,200 KB |
最終ジャッジ日時 | 2025-03-20 21:21:45 |
合計ジャッジ時間 | 2,427 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 22 |
ソースコード
import sysfrom collections import Counterfrom itertools import accumulatedef 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 = 1high = len(freqs)ans = high # Initialize with the maximum possible valuewhile low <= high:mid = (low + high) // 2if mid >= len(prefix):continue # This case shouldn't happen due to high being len(freqs)if prefix[mid] >= k:ans = midhigh = mid - 1else:low = mid + 1print(ans)if __name__ == "__main__":main()