結果

問題 No.3016 ハチマキおじさん
ユーザー ra5anchor
提出日時 2025-01-25 14:14:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 254 ms / 2,000 ms
コード長 624 bytes
コンパイル時間 596 ms
コンパイル使用メモリ 82,116 KB
実行使用メモリ 132,644 KB
最終ジャッジ日時 2025-01-25 23:12:36
合計ジャッジ時間 6,553 ms
ジャッジサーバーID
(参考情報)
judge2 / judge10
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

A.sort()
B.sort()

now = 0
for i in range(N-1):
    now += abs(A[i+1] - B[i])

mind = now
for i in range(N-1):
    now -= abs(A[i+1] - B[i])
    now += abs(A[i] - B[i])
    mind = min(mind, now)

now = 0
ansL = set()
for i in range(N-1):
    now += abs(A[i+1] - B[i])
if now == mind:
    ansL.add(A[0])
# print('ansL', ansL)
for i in range(N-1):
    now -= abs(A[i+1] - B[i])
    now += abs(A[i] - B[i])
    if now == mind:
        ansL.add(A[i+1])
# print('ansL', ansL)

print(len(ansL))
ans = list(ansL)
ans.sort()
print(*ans)
    
0