結果
| 問題 |
No.2114 01 Matching
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 16:03:04 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,136 bytes |
| コンパイル時間 | 260 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 164,048 KB |
| 最終ジャッジ日時 | 2025-06-12 16:03:33 |
| 合計ジャッジ時間 | 14,196 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 28 WA * 23 |
ソースコード
import sys
from collections import defaultdict
def main():
n, m, K = map(int, sys.stdin.readline().split())
B = list(map(int, sys.stdin.readline().split()))
R = list(map(int, sys.stdin.readline().split()))
t = min(n, m)
b_dict = defaultdict(list)
for b in B:
rem = b % K
b_dict[rem].append(b)
r_dict = defaultdict(list)
for r in R:
rem = r % K
r_dict[rem].append(r)
pair_costs = []
for rem in b_dict:
if rem not in r_dict:
continue
B_list = sorted(b_dict[rem], reverse=True)
R_list = sorted(r_dict[rem], reverse=True)
i = j = 0
while i < len(B_list) and j < len(R_list):
b_val = B_list[i]
r_val = R_list[j]
x = max(b_val, r_val)
diff = x - min(b_val, r_val)
cost = diff // K
pair_costs.append(cost)
i += 1
j += 1
if len(pair_costs) < t:
print(-1)
else:
pair_costs.sort()
total = sum(pair_costs[:t])
print(total)
if __name__ == "__main__":
main()
gew1fw