結果

問題 No.1767 BLUE to RED
コンテスト
ユーザー LyricalMaestro
提出日時 2025-11-12 21:24:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 294 ms / 2,000 ms
コード長 878 bytes
コンパイル時間 304 ms
コンパイル使用メモリ 82,712 KB
実行使用メモリ 198,972 KB
最終ジャッジ日時 2025-11-12 21:25:05
合計ジャッジ時間 6,875 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

## https://yukicoder.me/problems/no/1610

import heapq

MAX_INT = 10 ** 18

def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    A.append(-MAX_INT)
    A.append(MAX_INT)

    a_list = A + B
    a_list.sort()

    a_set = set(A)
    b_set = set(B)

    a_index = 0
    answer = 0
    max_value = -2 * MAX_INT
    for i in range(1, len(a_list)):
        x = a_list[i]
        if x in b_set:
            max_value = max(max_value, x - a_list[i - 1])
        if x in a_set:
            max_value = max(max_value, x - a_list[i - 1])
            total_value = a_list[i] - a_list[a_index]
            answer += total_value - max_value
            a_index = i
            max_value = -2 * MAX_INT
    print(answer)




    


    

                    

    









if __name__ == "__main__":
    main()
0