結果
問題 | No.3051 Make All Divisible |
ユーザー |
👑 |
提出日時 | 2025-02-03 23:09:10 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 769 bytes |
コンパイル時間 | 247 ms |
コンパイル使用メモリ | 82,292 KB |
実行使用メモリ | 77,156 KB |
最終ジャッジ日時 | 2025-02-08 15:05:09 |
合計ジャッジ時間 | 3,140 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 28 WA * 3 |
ソースコード
# 想定 WAfrom 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:cnt -= 1i = queue.popleft()if A[i] == C[i]:continueC[i] += Ktot += 1ma = C[i]queue.append(i)if ma <= tot:print(tot)else:print(-1)for _ in range(int(input())):solve()