結果

問題 No.489 株に挑戦
ユーザー 👑 rin204rin204
提出日時 2022-07-10 14:52:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 214 ms / 1,000 ms
コード長 1,896 bytes
コンパイル時間 396 ms
コンパイル使用メモリ 87,124 KB
実行使用メモリ 89,028 KB
最終ジャッジ日時 2023-09-01 03:19:42
合計ジャッジ時間 7,621 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 182 ms
86,628 KB
testcase_01 AC 171 ms
82,556 KB
testcase_02 AC 65 ms
71,136 KB
testcase_03 AC 67 ms
71,320 KB
testcase_04 AC 65 ms
71,328 KB
testcase_05 AC 66 ms
71,628 KB
testcase_06 AC 68 ms
71,332 KB
testcase_07 AC 65 ms
71,648 KB
testcase_08 AC 66 ms
71,332 KB
testcase_09 AC 67 ms
71,412 KB
testcase_10 AC 67 ms
71,456 KB
testcase_11 AC 68 ms
71,284 KB
testcase_12 AC 68 ms
71,136 KB
testcase_13 AC 68 ms
71,184 KB
testcase_14 AC 67 ms
71,452 KB
testcase_15 AC 122 ms
78,108 KB
testcase_16 AC 201 ms
87,708 KB
testcase_17 AC 116 ms
78,252 KB
testcase_18 AC 170 ms
83,248 KB
testcase_19 AC 161 ms
81,876 KB
testcase_20 AC 203 ms
87,964 KB
testcase_21 AC 147 ms
79,704 KB
testcase_22 AC 128 ms
78,728 KB
testcase_23 AC 162 ms
82,876 KB
testcase_24 AC 213 ms
89,028 KB
testcase_25 AC 70 ms
71,448 KB
testcase_26 AC 199 ms
88,308 KB
testcase_27 AC 210 ms
88,688 KB
testcase_28 AC 66 ms
71,336 KB
testcase_29 AC 67 ms
71,324 KB
testcase_30 AC 182 ms
88,544 KB
testcase_31 AC 180 ms
88,512 KB
testcase_32 AC 172 ms
82,824 KB
testcase_33 AC 214 ms
88,648 KB
testcase_34 AC 198 ms
87,596 KB
testcase_35 AC 155 ms
80,996 KB
testcase_36 AC 140 ms
78,756 KB
testcase_37 AC 170 ms
82,916 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class SegTree:
    def __init__(self, n, e, ope, lst=[]):
        self.N0 = 2 ** (n - 1).bit_length()
        self.e = e
        self.ope = ope
        self.data = [e] * (2 * self.N0)
        if lst:
            for i in range(n):
                self.data[self.N0 + i] = lst[i]
            for i in range(self.N0 - 1, 0, -1):
                self.data[i] = self.ope(self.data[2 * i], self.data[2 * i + 1])
    
    def build(self):
        for i in range(self.N0 - 1, 0, -1):
            self.data[i] = self.ope(self.data[2 * i], self.data[2 * i + 1])
                
    def update(self, i, x): #a_iの値をxに更新
        i += self.N0
        self.data[i] = x
        while i > 1:
            i >>= 1
            self.data[i] = self.ope(self.data[2 * i], self.data[2 * i + 1])
    
    def add(self, i, x):
        self.update(i, x + self.get(i))

    def set(self, i, x):
        self.data[self.N0 + i] = x
    
    def query(self, l, r): #区間[l, r)での演算結果
        if r <= l:
            return self.e
        lres = self.e
        rres = self.e
        l += self.N0
        r += self.N0
        while l < r:
            if l & 1:
                lres = self.ope(lres, self.data[l])
                l += 1
            if r & 1:
                r -= 1
                rres = self.ope(self.data[r], rres)
            l >>= 1
            r >>= 1
        return self.ope(lres, rres)
    
    def get(self, i): #a_iの値を返す
        return self.data[self.N0 + i]

n, d, k = map(int, input().split())
X = [int(input()) for _ in range(n)]
e = (1 << 30, -1)
def ope(l, r):
    if l[0] <= r[0]:
        return l
    else:
        return r

seg = SegTree(n, e, ope, [(x, i) for i, x in enumerate(X)])
ma = 0
for r in range(n):
    x, l = seg.query(max(r - d, 0), r)
    if X[r] - x > ma:
        ma = X[r] - x
        ans = (l, r)
print(ma * k)
if ma > 0:
    print(*ans)
    
0