結果

問題 No.3016 ハチマキおじさん
ユーザー ntuda
提出日時 2025-05-17 13:04:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 339 ms / 2,000 ms
コード長 622 bytes
コンパイル時間 436 ms
コンパイル使用メモリ 82,300 KB
実行使用メモリ 184,592 KB
最終ジャッジ日時 2025-05-17 13:04:20
合計ジャッジ時間 10,975 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
dic = defaultdict(list)
from itertools import accumulate
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
for i,a in enumerate(A,start = 1):
    dic[a].append(i)
A.sort()
B.sort()
C = [0]
D = [0]
for i in range(N-1):
    C.append(abs(A[i]-B[i]))
    D.append(abs(A[i+1]-B[i]))
C = list(accumulate(C))
D = list(accumulate(D))
ans = 10 ** 12
ans2 = set()
for i in range(N):
    tmp = C[i] + D[-1] - D[i]
    if ans > tmp:
        ans = tmp
        ans2 = {A[i]}
    elif ans == tmp:
        ans2.add(A[i])
print(len(ans2))
print(*sorted(list(ans2)))
0