結果

問題 No.2169 To Arithmetic
ユーザー tassei903tassei903
提出日時 2023-07-01 00:08:39
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,362 bytes
コンパイル時間 570 ms
コンパイル使用メモリ 87,048 KB
実行使用メモリ 128,276 KB
最終ジャッジ日時 2023-09-21 18:10:12
合計ジャッジ時間 20,858 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,248 KB
testcase_01 AC 74 ms
71,384 KB
testcase_02 AC 75 ms
71,532 KB
testcase_03 AC 76 ms
71,276 KB
testcase_04 AC 114 ms
77,796 KB
testcase_05 AC 110 ms
77,644 KB
testcase_06 AC 122 ms
77,932 KB
testcase_07 AC 121 ms
77,940 KB
testcase_08 AC 103 ms
77,340 KB
testcase_09 AC 353 ms
85,940 KB
testcase_10 AC 282 ms
104,800 KB
testcase_11 AC 674 ms
97,960 KB
testcase_12 AC 213 ms
100,928 KB
testcase_13 AC 482 ms
113,532 KB
testcase_14 AC 351 ms
94,636 KB
testcase_15 AC 218 ms
115,088 KB
testcase_16 AC 331 ms
94,652 KB
testcase_17 AC 720 ms
101,400 KB
testcase_18 AC 399 ms
90,116 KB
testcase_19 AC 930 ms
120,492 KB
testcase_20 AC 956 ms
121,064 KB
testcase_21 AC 902 ms
120,192 KB
testcase_22 AC 905 ms
120,676 KB
testcase_23 AC 914 ms
120,336 KB
testcase_24 AC 823 ms
116,420 KB
testcase_25 RE -
testcase_26 AC 1,029 ms
116,980 KB
testcase_27 AC 860 ms
128,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda :sys.stdin.readline()[:-1]
ni = lambda :int(input())
na = lambda :list(map(int,input().split()))
yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES")
no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO")
#######################################################################
def cross3(a, b, c):
    return (b[0]-a[0])*(c[1]-a[1]) - (b[1]-a[1])*(c[0]-a[0])

# ps = [(x, y), ...]: ソートされた座標list
def convex_hull(ps):
    qs = []
    N = len(ps)
    for p in ps:
        # 一直線上で高々2点にする場合は ">=" にする
        while len(qs) > 1 and cross3(qs[-1], qs[-2], p) < 0:
            qs.pop()
        qs.append(p)
    return qs
n, q = na()
a = na()
s = sum(a)
ps = convex_hull([(i, a[i]) for i in range(n)])
d = [(ni(), i) for i in range(q)]
d = sorted(d)[::-1]
j = 0
m = len(ps)
ans = [None] * q

from bisect import bisect_left as bl
z = [a[i+1]-a[i] for i in range(n-1)]
z = sorted(z)
rui = [0]
for i in range(n-1):
    rui.append(rui[-1] + z[i])
for i in range(q):
    while j < m-1 and d[i][0]*(ps[j+1][0]-ps[j][0]) < ps[j+1][1]-ps[j][1]:
        j += 1
    y = ps[j][1]
    x = ps[j][0]
    D = d[i][0]
    p = bl(z, D)
    #print(d[i][1],j, y - x * D-a[0]+ D * p - rui[p])
    ans[d[i][1]] = y - x * D-a[0]+ D * p - rui[p]
print(*ans, sep="\n")
0