結果

問題 No.489 株に挑戦
ユーザー H3PO4H3PO4
提出日時 2021-02-27 13:13:49
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,638 bytes
コンパイル時間 165 ms
コンパイル使用メモリ 82,688 KB
実行使用メモリ 82,240 KB
最終ジャッジ日時 2024-04-10 15:35:47
合計ジャッジ時間 5,670 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 WA -
testcase_02 AC 33 ms
53,224 KB
testcase_03 AC 31 ms
53,920 KB
testcase_04 AC 31 ms
54,320 KB
testcase_05 AC 35 ms
54,212 KB
testcase_06 AC 33 ms
53,824 KB
testcase_07 WA -
testcase_08 RE -
testcase_09 AC 36 ms
53,796 KB
testcase_10 RE -
testcase_11 AC 34 ms
54,140 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 155 ms
80,476 KB
testcase_17 RE -
testcase_18 AC 131 ms
81,996 KB
testcase_19 AC 133 ms
81,540 KB
testcase_20 AC 164 ms
80,460 KB
testcase_21 WA -
testcase_22 AC 92 ms
76,700 KB
testcase_23 RE -
testcase_24 AC 169 ms
80,324 KB
testcase_25 AC 34 ms
53,700 KB
testcase_26 AC 140 ms
80,188 KB
testcase_27 RE -
testcase_28 AC 33 ms
53,552 KB
testcase_29 AC 33 ms
53,076 KB
testcase_30 WA -
testcase_31 AC 135 ms
80,576 KB
testcase_32 WA -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

class SegmentTree:
    """
    https://qiita.com/dn6049949/items/afa12d5d079f518de368 から拝借しています。
    """

    def __init__(self, size, f=lambda x, y: max(x, y), default=0):
        self.size = 2 ** (size - 1).bit_length()
        self.default = default
        self.dat = [default] * (self.size * 2)
        self.f = f

    def initialize(self, A):
        for i, a in enumerate(A):
            self.dat[self.size + i] = a
        for i in range(self.size - 2, -1, -1):
            self.dat[i] = self.f(self.dat[2 * i + 1], self.dat[2 * i + 2])

    def update(self, i, x):
        i += self.size
        self.dat[i] = x
        while i > 0:
            i >>= 1
            self.dat[i] = self.f(self.dat[i * 2], self.dat[i * 2 + 1])

    def query(self, l, r):
        """半開区間[l,r)"""
        l += self.size
        r += self.size
        lres, rres = self.default, self.default
        while l < r:
            if l & 1:
                lres = self.f(lres, self.dat[l])
                l += 1

            if r & 1:
                r -= 1
                rres = self.f(self.dat[r], rres)
            l >>= 1
            r >>= 1
        res = self.f(lres, rres)
        return res


N, D, K = map(int, input().split())
S = SegmentTree(N + 1)
X = [int(input()) for _ in range(N)]
S.initialize([0] + X)

p_max = 0
lidx = 0
for i, x in enumerate(X, 1):
    M = S.query(i, min(i + D, N) + 1)
    profit = K * (M - x)
    if p_max < profit:
        p_max = profit
        lidx = i - 1
print(p_max)
if p_max:
    M = X[lidx] + p_max // K
    ridx = X[lidx:min(lidx + D + 1, N)].index(M) + lidx
    print(lidx, ridx)
0