結果

問題 No.1391 ±1 Abs Sum
ユーザー ayaoniayaoni
提出日時 2021-02-12 21:41:11
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 723 bytes
コンパイル時間 540 ms
コンパイル使用メモリ 86,688 KB
実行使用メモリ 104,392 KB
最終ジャッジ日時 2023-09-27 03:23:06
合計ジャッジ時間 6,135 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,136 KB
testcase_01 AC 70 ms
71,356 KB
testcase_02 AC 72 ms
71,004 KB
testcase_03 AC 72 ms
71,308 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 106 ms
93,684 KB
testcase_15 WA -
testcase_16 AC 117 ms
101,696 KB
testcase_17 WA -
testcase_18 AC 122 ms
100,092 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 127 ms
100,080 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 71 ms
71,176 KB
testcase_36 AC 127 ms
101,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())


N,K = MI()
A = LI()

ans0 = 0
for i in range(K):
    ans0 += abs(A[i]-A[0])

for i in range(K,N):
    ans0 -= abs(A[i]-A[0])

ans1 = 0
for i in range(N-1,N-K-1,-1):
    ans1 += abs(A[i]-A[0])
for i in range(N-K-1,-1,-1):
    ans1 -= abs(A[i]-A[0])

print(min(ans0,ans1))
0