結果

問題 No.1767 BLUE to RED
ユーザー kohei2019kohei2019
提出日時 2023-06-22 22:56:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 308 ms / 2,000 ms
コード長 659 bytes
コンパイル時間 708 ms
コンパイル使用メモリ 87,136 KB
実行使用メモリ 149,852 KB
最終ジャッジ日時 2023-09-12 17:14:09
合計ジャッジ時間 9,059 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,176 KB
testcase_01 AC 69 ms
71,288 KB
testcase_02 AC 70 ms
71,400 KB
testcase_03 AC 69 ms
71,368 KB
testcase_04 AC 71 ms
71,400 KB
testcase_05 AC 72 ms
71,288 KB
testcase_06 AC 70 ms
71,612 KB
testcase_07 AC 76 ms
75,804 KB
testcase_08 AC 79 ms
76,392 KB
testcase_09 AC 218 ms
118,456 KB
testcase_10 AC 250 ms
125,720 KB
testcase_11 AC 231 ms
123,420 KB
testcase_12 AC 212 ms
118,300 KB
testcase_13 AC 271 ms
149,852 KB
testcase_14 AC 308 ms
143,848 KB
testcase_15 AC 299 ms
143,708 KB
testcase_16 AC 302 ms
143,536 KB
testcase_17 AC 300 ms
143,500 KB
testcase_18 AC 304 ms
143,648 KB
testcase_19 AC 302 ms
143,472 KB
testcase_20 AC 299 ms
143,452 KB
testcase_21 AC 302 ms
144,972 KB
testcase_22 AC 302 ms
143,572 KB
testcase_23 AC 301 ms
143,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M = map(int,input().split())
lsA = list(map(int,input().split()))
lsB = list(map(int,input().split()))
# Aを0,Bを1とする
lsAB = [(-10**10,0)]
for i in range(N):
    lsAB.append((lsA[i],0))
for i in range(M):
    lsAB.append((lsB[i],1))
lsAB.append((10**10,0))
lsAB.sort()
br = -10**10
ans = 0
ii = 0
while ii <= N+M:
    rs = lsAB[ii][0]
    lsBB = [rs]
    ii += 1
    while lsAB[ii][1]==1:
        lsBB.append(lsAB[ii][0])
        ii += 1
    if len(lsBB)<=1:
        continue
    lsBB.append(lsAB[ii][0])
    sm = lsBB[-1]-lsBB[0]
    maxd = 0
    for i in range(len(lsBB)-1):
        maxd = max(maxd,lsBB[i+1]-lsBB[i])
    ans += sm-maxd
print(ans)
0