結果

問題 No.489 株に挑戦
ユーザー roarisroaris
提出日時 2019-08-21 19:28:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 283 ms / 1,000 ms
コード長 1,635 bytes
コンパイル時間 252 ms
コンパイル使用メモリ 86,960 KB
実行使用メモリ 98,432 KB
最終ジャッジ日時 2023-09-27 06:05:00
合計ジャッジ時間 8,263 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 246 ms
93,536 KB
testcase_01 AC 207 ms
88,240 KB
testcase_02 AC 81 ms
71,664 KB
testcase_03 AC 83 ms
71,464 KB
testcase_04 AC 88 ms
71,756 KB
testcase_05 AC 85 ms
71,892 KB
testcase_06 AC 92 ms
72,260 KB
testcase_07 AC 89 ms
72,368 KB
testcase_08 AC 85 ms
71,668 KB
testcase_09 AC 84 ms
72,392 KB
testcase_10 AC 82 ms
72,260 KB
testcase_11 AC 83 ms
72,504 KB
testcase_12 AC 87 ms
72,308 KB
testcase_13 AC 89 ms
72,312 KB
testcase_14 AC 90 ms
72,484 KB
testcase_15 AC 160 ms
79,908 KB
testcase_16 AC 250 ms
84,180 KB
testcase_17 AC 137 ms
79,340 KB
testcase_18 AC 219 ms
82,680 KB
testcase_19 AC 210 ms
82,124 KB
testcase_20 AC 268 ms
95,508 KB
testcase_21 AC 179 ms
84,196 KB
testcase_22 AC 158 ms
79,844 KB
testcase_23 AC 209 ms
89,268 KB
testcase_24 AC 277 ms
97,884 KB
testcase_25 AC 85 ms
72,364 KB
testcase_26 AC 233 ms
97,068 KB
testcase_27 AC 216 ms
84,448 KB
testcase_28 AC 84 ms
71,600 KB
testcase_29 AC 86 ms
71,732 KB
testcase_30 AC 268 ms
98,432 KB
testcase_31 AC 239 ms
97,404 KB
testcase_32 AC 206 ms
89,316 KB
testcase_33 AC 283 ms
95,772 KB
testcase_34 AC 274 ms
95,380 KB
testcase_35 AC 185 ms
86,064 KB
testcase_36 AC 158 ms
81,368 KB
testcase_37 AC 228 ms
88,884 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
from bisect import bisect_left

class SegmentTree:
    def __init__(self, N, mode):
        n_ = 1
         
        while n_ < N:
            n_ *= 2
             
        self.n = n_
        self.mode = mode
         
        if self.mode == min:
            self.arr = [2**31-1] * (2*self.n - 1)
        elif self.mode == max:
            self.arr = [-2**31+1] * (2*self.n - 1)
     
    def update(self, k, a):
        k += self.n - 1
        self.arr[k] = a
         
        while k > 0:
            k = (k - 1) // 2
            self.arr[k] = self.mode(self.arr[2*k+1], self.arr[2*k+2])
     
    def query(self, l, r):
        L, R = l + self.n, r + self.n
         
        if self.mode == min:
            res = 2**31-1
        else:
            res = -2**31+1
         
        while L < R:
            if R & 1:
                R -= 1
                res = self.mode(res, self.arr[R-1])
             
            if L & 1:
                res = self.mode(res, self.arr[L-1])
                L += 1
             
            L >>= 1
            R >>= 1
         
        return res

N, D, K = map(int, input().split())
x = [int(input()) for _ in range(N)]
st = SegmentTree(N, max)
d = defaultdict(list)

for i in range(N):
    st.update(i, x[i])
    d[x[i]].append(i)

ans = 0
s, e = None, None

for i in range(N-1):
    before = x[i]
    after = st.query(i+1, min(N, i+1+D))
    profit = (after - before) * K
    
    if profit > ans:
        s = i
        index = bisect_left(d[after], i)
        e = d[after][index]
        ans = profit
        
print(ans)

if ans > 0:
    print(s, e)
0