結果
| 問題 |
No.2334 Distinct Cards
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 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 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()
lam6er