結果

問題 No.2698 Many Asakatsu
ユーザー 👑 rin204rin204
提出日時 2024-03-22 22:32:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 881 ms / 2,000 ms
コード長 1,381 bytes
コンパイル時間 217 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 110,564 KB
最終ジャッジ日時 2024-03-22 22:32:16
合計ジャッジ時間 14,724 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,460 KB
testcase_01 AC 38 ms
53,460 KB
testcase_02 AC 38 ms
53,460 KB
testcase_03 AC 38 ms
53,460 KB
testcase_04 AC 38 ms
53,460 KB
testcase_05 AC 39 ms
53,460 KB
testcase_06 AC 39 ms
53,460 KB
testcase_07 AC 101 ms
75,656 KB
testcase_08 AC 95 ms
75,548 KB
testcase_09 AC 96 ms
75,680 KB
testcase_10 AC 92 ms
75,548 KB
testcase_11 AC 163 ms
77,276 KB
testcase_12 AC 140 ms
76,428 KB
testcase_13 AC 124 ms
76,664 KB
testcase_14 AC 119 ms
76,800 KB
testcase_15 AC 146 ms
76,600 KB
testcase_16 AC 147 ms
76,700 KB
testcase_17 AC 125 ms
76,424 KB
testcase_18 AC 126 ms
76,916 KB
testcase_19 AC 143 ms
94,760 KB
testcase_20 AC 128 ms
94,312 KB
testcase_21 AC 143 ms
94,996 KB
testcase_22 AC 825 ms
110,228 KB
testcase_23 AC 819 ms
109,000 KB
testcase_24 AC 849 ms
109,372 KB
testcase_25 AC 813 ms
110,156 KB
testcase_26 AC 861 ms
109,380 KB
testcase_27 AC 862 ms
109,256 KB
testcase_28 AC 881 ms
95,644 KB
testcase_29 AC 510 ms
110,304 KB
testcase_30 AC 429 ms
110,564 KB
testcase_31 AC 839 ms
100,836 KB
testcase_32 AC 649 ms
109,588 KB
testcase_33 AC 137 ms
94,388 KB
testcase_34 AC 788 ms
110,260 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve(n, m, A, B, Q, x, C):
    def f(i, x):
        a, b = A[i], B[i]
        x -= a
        if b == 0:
            return abs(x) * m
        p = x // b
        if p < 0:
            return m * (b * (m - 1)) // 2 - x * m
        elif p >= m:
            return x * m - m * (b * (m - 1)) // 2
        else:
            ret = x * (p + 1) - (p + 1) * (b * p) // 2
            ret += (m - 1 - p) * (b * (p + 1) + b * (m - 1)) // 2 - x * (m - 1 - p)
            return ret

    P = [0]
    thr = []
    i = 1
    while i < n:
        bi = P[-1]
        l = 0
        r = 1 << 60

        while r - l > 1:
            mid = (l + r) // 2
            if f(bi, mid) > f(i, mid):
                r = mid
            else:
                l = mid

        if not thr or thr[-1] <= r:
            P.append(i)
            thr.append(r)
            i += 1
        else:
            P.pop()
            thr.pop()

    p = 0
    ans = []

    for _ in range(Q):
        while p < len(P) - 1 and x >= thr[p]:
            p += 1
        ans.append(P[p] + 1)
        x += C[P[p]]
    return ans


if __name__ == "__main__":
    n, m = map(int, input().split())
    A = [0] * n
    B = [0] * n
    for i in range(n):
        A[i], B[i] = map(int, input().split())

    Q, x = map(int, input().split())
    C = list(map(int, input().split()))

    res = solve(n, m, A, B, Q, x, C)
    print(*res)
0