結果

問題 No.1012 荷物収集
ユーザー neterukunneterukun
提出日時 2020-03-20 23:28:07
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,157 bytes
コンパイル時間 295 ms
コンパイル使用メモリ 82,852 KB
実行使用メモリ 103,568 KB
最終ジャッジ日時 2024-05-09 07:35:02
合計ジャッジ時間 12,085 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
52,096 KB
testcase_01 AC 36 ms
52,132 KB
testcase_02 AC 34 ms
51,840 KB
testcase_03 AC 34 ms
52,352 KB
testcase_04 AC 202 ms
103,372 KB
testcase_05 AC 196 ms
103,296 KB
testcase_06 AC 196 ms
103,532 KB
testcase_07 AC 186 ms
103,296 KB
testcase_08 AC 193 ms
103,296 KB
testcase_09 AC 190 ms
103,296 KB
testcase_10 AC 196 ms
103,400 KB
testcase_11 AC 185 ms
103,568 KB
testcase_12 AC 189 ms
103,208 KB
testcase_13 AC 195 ms
103,548 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
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 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 37 ms
52,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, q = map(int, input().split())
info = [list(map(int, input().split())) for i in range(n)]
query = list(map(int, input().split()))

info = sorted(info)
ans = [0] * q

ind = 0
weight = 0
for i in range(q):
    tmp = 0
    pos = query[i]
    if i - 1 >= 0:
        prv_pos = query[i - 1]
    else:
        prv_pos = pos
    while True:
        if ind >= n:
            break
        x, w = info[ind]
        if x <= pos:
            tmp += w
            ans[i] += w * (pos - x)
            ind += 1
        else:
            break
    if i - 1 >= 0:
        ans[i] += (pos - prv_pos) * weight + ans[i - 1]
    weight += tmp

ans2 = [0] * q
ind = n - 1
weight = 0
for i in range(q)[::-1]:
    tmp = 0
    pos = query[i]
    if i + 1 < q:
        prv_pos = query[i + 1]
    else:
        prv_pos = pos
    while True:
        if ind < 0:
            break
        x, w = info[ind]
        if x >= pos:
            tmp += w
            ans2[i] += w * abs(pos - x)
            ind -= 1
        else:
            break
    if i + 1 < q:
        ans2[i] += abs(pos - prv_pos) * weight + ans2[i + 1]
    weight += tmp

for i in range(q):
    print(ans[i] + ans2[i])
0