結果

問題 No.2603 Tone Correction
ユーザー mkawa2mkawa2
提出日時 2024-01-13 22:12:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 189 ms / 2,000 ms
コード長 1,209 bytes
コンパイル時間 306 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 134,556 KB
最終ジャッジ日時 2024-01-13 22:12:32
合計ジャッジ時間 7,268 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,460 KB
testcase_01 AC 35 ms
53,460 KB
testcase_02 AC 35 ms
53,460 KB
testcase_03 AC 46 ms
64,308 KB
testcase_04 AC 47 ms
64,308 KB
testcase_05 AC 47 ms
64,308 KB
testcase_06 AC 46 ms
64,308 KB
testcase_07 AC 47 ms
64,308 KB
testcase_08 AC 47 ms
64,308 KB
testcase_09 AC 46 ms
64,308 KB
testcase_10 AC 46 ms
64,308 KB
testcase_11 AC 47 ms
64,308 KB
testcase_12 AC 47 ms
64,308 KB
testcase_13 AC 187 ms
133,908 KB
testcase_14 AC 189 ms
133,908 KB
testcase_15 AC 177 ms
134,300 KB
testcase_16 AC 177 ms
133,912 KB
testcase_17 AC 175 ms
134,296 KB
testcase_18 AC 175 ms
134,140 KB
testcase_19 AC 175 ms
134,292 KB
testcase_20 AC 176 ms
134,168 KB
testcase_21 AC 187 ms
134,292 KB
testcase_22 AC 174 ms
134,556 KB
testcase_23 AC 157 ms
112,772 KB
testcase_24 AC 156 ms
112,768 KB
testcase_25 AC 156 ms
112,904 KB
testcase_26 AC 157 ms
112,772 KB
testcase_27 AC 156 ms
113,156 KB
testcase_28 AC 155 ms
112,516 KB
testcase_29 AC 157 ms
112,520 KB
testcase_30 AC 157 ms
112,516 KB
testcase_31 AC 156 ms
112,520 KB
testcase_32 AC 157 ms
112,516 KB
testcase_33 AC 34 ms
53,460 KB
testcase_34 AC 137 ms
132,516 KB
testcase_35 AC 136 ms
132,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(1000005)
# sys.set_int_max_str_digits(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()

dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = -1-(-1 << 31)
# inf = -1-(-1 << 63)
# md = 10**9+7
md = 998244353

n,m=LI()
aa=LI()
bb=LI()
for i in range(n):
    aa[i]-=bb[i]
    aa[i]%=m
aa.append(0)
# print(aa)
dd=[aa[0]]+[(aa[i+1]-aa[i])%m for i in range(n)]
dd.sort()
l,r=0,n
ans=0
while l<r:
    if dd[l]+dd[r]==m:
        ans+=dd[l]
        l+=1
        r-=1
    elif dd[l]+dd[r]<m:
        ans+=dd[l]
        dd[r]+=dd[l]
        l+=1
    else:
        cur=m-dd[r]
        ans+=cur
        dd[l]-=cur
        r-=1
    # print(l,r,ans,dd)
print(ans)
0