結果
問題 | No.3051 Make All Divisible |
ユーザー |
👑 |
提出日時 | 2025-02-03 23:24:20 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 65 ms / 2,000 ms |
コード長 | 756 bytes |
コンパイル時間 | 168 ms |
コンパイル使用メモリ | 82,352 KB |
実行使用メモリ | 77,068 KB |
最終ジャッジ日時 | 2025-02-08 15:05:11 |
合計ジャッジ時間 | 2,671 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 31 |
ソースコード
from collections import dequedef solve():n, K = map(int, input().split())A = list(map(int, input().split()))A.sort()C = [a % K for a in A]if sum(C) % K != 0:print(-1)returnqueue = deque()pos = [[] for _ in range(K)]for i, c in enumerate(C):pos[c].append(i)for row in pos:queue.extend(row)tot = sum(C) // Kma = max(C)cnt = K * K + 10while ma > tot and cnt > 0 and queue:i = queue.popleft()if A[i] == C[i]:continuecnt -= 1C[i] += Ktot += 1ma = C[i]queue.append(i)if ma <= tot:print(tot)else:print(-1)for _ in range(int(input())):solve()