結果

問題 No.1391 ±1 Abs Sum
ユーザー convexineqconvexineq
提出日時 2021-02-13 14:26:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 209 ms / 2,000 ms
コード長 453 bytes
コンパイル時間 750 ms
コンパイル使用メモリ 87,088 KB
実行使用メモリ 126,560 KB
最終ジャッジ日時 2023-09-27 22:53:29
合計ジャッジ時間 8,198 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,204 KB
testcase_01 AC 76 ms
71,280 KB
testcase_02 AC 77 ms
71,056 KB
testcase_03 AC 76 ms
71,084 KB
testcase_04 AC 75 ms
71,240 KB
testcase_05 AC 77 ms
71,292 KB
testcase_06 AC 75 ms
71,172 KB
testcase_07 AC 76 ms
70,896 KB
testcase_08 AC 75 ms
71,212 KB
testcase_09 AC 77 ms
71,440 KB
testcase_10 AC 74 ms
71,164 KB
testcase_11 AC 209 ms
126,560 KB
testcase_12 AC 179 ms
110,792 KB
testcase_13 AC 205 ms
122,232 KB
testcase_14 AC 170 ms
97,932 KB
testcase_15 AC 189 ms
102,240 KB
testcase_16 AC 177 ms
112,740 KB
testcase_17 AC 162 ms
103,704 KB
testcase_18 AC 172 ms
106,876 KB
testcase_19 AC 202 ms
112,308 KB
testcase_20 AC 190 ms
120,368 KB
testcase_21 AC 155 ms
106,712 KB
testcase_22 AC 158 ms
106,632 KB
testcase_23 AC 175 ms
107,180 KB
testcase_24 AC 158 ms
111,128 KB
testcase_25 AC 175 ms
109,716 KB
testcase_26 AC 167 ms
107,240 KB
testcase_27 AC 167 ms
100,456 KB
testcase_28 AC 179 ms
106,768 KB
testcase_29 AC 156 ms
109,812 KB
testcase_30 AC 163 ms
103,176 KB
testcase_31 AC 181 ms
114,056 KB
testcase_32 AC 122 ms
95,460 KB
testcase_33 AC 128 ms
100,628 KB
testcase_34 AC 150 ms
107,296 KB
testcase_35 AC 74 ms
71,364 KB
testcase_36 AC 152 ms
109,500 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def f(L,R,x):
    return -g(0,n,x) + 2*g(L,R,x)

def g(i,j,x):
    return h(i,x)*(1 if i <= x else -1) + h(j,x)*(-1 if j <= x else 1)

def h(j,x):
    return a[x]*(x-j) - (s[j]-s[x])

n,k = map(int,input().split())
*a, = map(int,input().split())

s = a + [0]
for i in range(n)[::-1]:
    s[i] += s[i+1]

L = 0
ans = 1<<60
for i in range(n):
    while L+k < n and a[i]-a[L] > a[L+k]-a[i]:
        L += 1
    v = f(L,L+k,i)
    ans = min(v,ans)
print(ans)
0