結果
| 問題 | No.3016 ハチマキおじさん |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-01-25 13:25:52 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 894 bytes |
| 記録 | |
| コンパイル時間 | 335 ms |
| コンパイル使用メモリ | 82,600 KB |
| 実行使用メモリ | 143,804 KB |
| 最終ジャッジ日時 | 2025-01-25 22:46:34 |
| 合計ジャッジ時間 | 6,595 ms |
|
ジャッジサーバーID (参考情報) |
judge11 / judge7 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 29 WA * 2 |
ソースコード
import sys
input = lambda: sys.stdin.readline().rstrip()
def main():
# 入力
N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
# 計算・出力
dp = [0, 10**16]
ans = []
for i, b in enumerate(B):
ndp = [10**16, 10**16]
# i 番目を残すか?
# まだ残さない
ndp[0] = dp[0] + abs(A[i] - b)
# もう残してる
if i > 0:
ndp[1] = dp[1] + abs(A[i+1] - b)
# 今残す
ndp1 = dp[0] + abs(A[i+1] - b)
if ndp1 < ndp[1]:
ans = [A[i]]
ndp[1] = ndp1
elif ndp1 == ndp[1]:
ans.append(A[i])
dp = ndp
# print(dp)
if dp[0] < dp[1]:
ans = [A[-1]]
ans = sorted(list(set(ans)))
print(len(ans))
print(*ans)
if __name__ == "__main__":
main()