結果

問題 No.489 株に挑戦
ユーザー brthyyjpbrthyyjp
提出日時 2020-09-08 02:19:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 219 ms / 1,000 ms
コード長 1,729 bytes
コンパイル時間 419 ms
コンパイル使用メモリ 87,148 KB
実行使用メモリ 83,712 KB
最終ジャッジ日時 2023-09-27 06:17:45
合計ジャッジ時間 6,234 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 142 ms
82,464 KB
testcase_01 AC 153 ms
80,640 KB
testcase_02 AC 63 ms
71,448 KB
testcase_03 AC 64 ms
71,428 KB
testcase_04 AC 65 ms
71,188 KB
testcase_05 AC 63 ms
71,452 KB
testcase_06 AC 65 ms
71,448 KB
testcase_07 AC 64 ms
71,392 KB
testcase_08 AC 65 ms
71,440 KB
testcase_09 AC 62 ms
71,292 KB
testcase_10 AC 63 ms
71,604 KB
testcase_11 AC 65 ms
71,456 KB
testcase_12 AC 64 ms
71,524 KB
testcase_13 AC 66 ms
71,680 KB
testcase_14 AC 66 ms
71,600 KB
testcase_15 AC 112 ms
78,104 KB
testcase_16 AC 219 ms
83,476 KB
testcase_17 AC 105 ms
78,556 KB
testcase_18 AC 160 ms
80,712 KB
testcase_19 AC 158 ms
80,480 KB
testcase_20 AC 179 ms
82,688 KB
testcase_21 AC 138 ms
79,792 KB
testcase_22 AC 112 ms
78,244 KB
testcase_23 AC 133 ms
80,760 KB
testcase_24 AC 182 ms
83,620 KB
testcase_25 AC 64 ms
71,524 KB
testcase_26 AC 163 ms
82,820 KB
testcase_27 AC 187 ms
83,712 KB
testcase_28 AC 65 ms
71,484 KB
testcase_29 AC 64 ms
71,604 KB
testcase_30 AC 167 ms
83,248 KB
testcase_31 AC 143 ms
82,864 KB
testcase_32 AC 152 ms
81,196 KB
testcase_33 AC 188 ms
83,544 KB
testcase_34 AC 177 ms
82,840 KB
testcase_35 AC 138 ms
80,296 KB
testcase_36 AC 119 ms
78,900 KB
testcase_37 AC 158 ms
80,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import io, os
input = sys.stdin.buffer.readline
#input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
n, d, k = map(int, input().split())
X = [(int(input()), i) for i in range(n)]

class SegTree:
    def __init__(self, init_val, ide_ele, segfunc):
        self.n = len(init_val)
        self.num = 2**(self.n-1).bit_length()
        self.ide_ele = ide_ele
        self.segfunc = segfunc
        self.seg = [ide_ele]*2*self.num
        # set_val
        for i in range(self.n):
            self.seg[i+self.num] = init_val[i]
        # built
        for i in range(self.num-1, 0, -1):
            self.seg[i] = self.segfunc(self.seg[2*i], self.seg[2*i+1])

    def update(self, k, x):
        k += self.num
        self.seg[k] = x
        while k:
            k = k >> 1
            self.seg[k] = self.segfunc(self.seg[2*k], self.seg[2*k+1])

    def query(self, l, r):
        if r <= l:
            return self.ide_ele
        l += self.num
        r += self.num
        res = self.ide_ele
        while l < r:
            if r & 1:
                r -= 1
                res = self.segfunc(res, self.seg[r])
            if l & 1:
                res = self.segfunc(res, self.seg[l])
                l += 1
            l = l >> 1
            r = r >> 1
        return res

def segfunc(x, y):
    if x[0] > y[0]:
        return x
    elif x[0] < y[0]:
        return y
    else:
        if x[1] < y[1]:
            return x
        else:
            return y

seg = SegTree(X, (-1, -1), segfunc)

M = 0
for l in range(n):
    r = min(l+d, n-1)
    s, t = seg.query(l, r+1)
    temp = k*(s-X[l][0])
    if temp > M:
        M = temp
        ans = (l, t)
if M != 0:
    print(M)
    print(*ans)
else:
    print(M)
0