結果

問題 No.1767 BLUE to RED
ユーザー SidewaysOwlSidewaysOwl
提出日時 2021-11-27 09:44:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 332 ms / 2,000 ms
コード長 724 bytes
コンパイル時間 287 ms
コンパイル使用メモリ 86,716 KB
実行使用メモリ 142,856 KB
最終ジャッジ日時 2023-09-12 13:07:13
合計ジャッジ時間 7,562 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,216 KB
testcase_01 AC 71 ms
71,156 KB
testcase_02 AC 71 ms
71,140 KB
testcase_03 AC 72 ms
71,164 KB
testcase_04 AC 75 ms
71,132 KB
testcase_05 AC 73 ms
71,144 KB
testcase_06 AC 74 ms
71,220 KB
testcase_07 AC 102 ms
76,036 KB
testcase_08 AC 80 ms
76,244 KB
testcase_09 AC 238 ms
124,772 KB
testcase_10 AC 263 ms
119,556 KB
testcase_11 AC 247 ms
125,920 KB
testcase_12 AC 240 ms
125,100 KB
testcase_13 AC 289 ms
141,576 KB
testcase_14 AC 328 ms
142,676 KB
testcase_15 AC 329 ms
142,540 KB
testcase_16 AC 328 ms
142,460 KB
testcase_17 AC 331 ms
142,672 KB
testcase_18 AC 332 ms
142,680 KB
testcase_19 AC 331 ms
142,512 KB
testcase_20 AC 329 ms
142,448 KB
testcase_21 AC 330 ms
142,856 KB
testcase_22 AC 332 ms
142,636 KB
testcase_23 AC 330 ms
142,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m = map(int,input().split())
a = [-(10**9 + 1)] + list(map(int,input().split())) + [2*10**9 + 1] 
b = list(map(int,input().split()))
ab = []
for i in range(n+2):
    ab.append([a[i],1])
for i in range(m):
    ab.append([b[i],0])
ab.sort()
flg = 1
max_ = 0
sum_ = 0
ans = 0
for i in range(n+m+2):
    idx,color = ab[i]
    if color == 1 and flg == 0:
        max_ = max(ab[i][0] - ab[i-1][0] ,max_)
        sum_ += ab[i][0] - ab[i-1][0]
        ans += sum_ - max_
    elif color == 0 and flg == 1:
        max_ = ab[i][0] - ab[i-1][0]
        sum_ = ab[i][0] - ab[i-1][0]
    elif color == 0 and flg == 0:
        max_ = max(ab[i][0] - ab[i-1][0] ,max_)
        sum_ += ab[i][0] - ab[i-1][0]
    flg = color
    
print(ans)
0