結果

問題 No.489 株に挑戦
ユーザー roarisroaris
提出日時 2019-08-09 18:59:53
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,433 bytes
コンパイル時間 659 ms
コンパイル使用メモリ 86,940 KB
実行使用メモリ 106,668 KB
最終ジャッジ日時 2023-09-26 13:19:40
合計ジャッジ時間 21,417 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 753 ms
99,392 KB
testcase_01 AC 637 ms
90,796 KB
testcase_02 AC 91 ms
71,552 KB
testcase_03 AC 91 ms
71,616 KB
testcase_04 AC 92 ms
71,496 KB
testcase_05 AC 92 ms
71,792 KB
testcase_06 AC 96 ms
72,412 KB
testcase_07 AC 95 ms
72,260 KB
testcase_08 AC 92 ms
71,524 KB
testcase_09 AC 102 ms
76,616 KB
testcase_10 AC 101 ms
76,584 KB
testcase_11 AC 101 ms
76,304 KB
testcase_12 AC 102 ms
76,608 KB
testcase_13 AC 100 ms
76,624 KB
testcase_14 AC 101 ms
76,796 KB
testcase_15 AC 229 ms
80,180 KB
testcase_16 AC 921 ms
87,132 KB
testcase_17 AC 287 ms
82,224 KB
testcase_18 AC 683 ms
84,812 KB
testcase_19 AC 687 ms
85,900 KB
testcase_20 TLE -
testcase_21 AC 427 ms
85,712 KB
testcase_22 AC 267 ms
82,292 KB
testcase_23 AC 537 ms
93,308 KB
testcase_24 TLE -
testcase_25 AC 102 ms
76,532 KB
testcase_26 AC 969 ms
106,304 KB
testcase_27 AC 995 ms
88,468 KB
testcase_28 AC 89 ms
71,324 KB
testcase_29 AC 89 ms
71,536 KB
testcase_30 AC 994 ms
106,264 KB
testcase_31 AC 908 ms
106,668 KB
testcase_32 AC 762 ms
94,140 KB
testcase_33 TLE -
testcase_34 TLE -
testcase_35 AC 623 ms
88,748 KB
testcase_36 AC 335 ms
82,896 KB
testcase_37 AC 700 ms
92,780 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

class SegmentTree:
    def __init__(self, N):
        n_ = 1
        while n_ < N:
            n_ *= 2
        self.n = n_
        self.arr = [-10 ** 18] * (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] = max(self.arr[2*k + 1], self.arr[2*k + 2])
        
    def query_sub(self, a, b, k, l, r):
        if r <= a or b <= l:
            return -10 ** 18
        
        if a <= l and r <= b:
            return self.arr[k]
        else:
            vl = self.query_sub(a, b, 2*k + 1, l, (l+r) / 2)
            vr = self.query_sub(a, b, 2*k + 2, (l+r) / 2, r)
            return max(vl, vr)
    
    def query(self, a, b):
        return self.query_sub(a, b, 0, 0, self.n)

N, D, K = map(int, input().split())
x = [int(input()) for _ in range(N)]
seg_tree = SegmentTree(N)

for i in range(N):
    seg_tree.update(i, x[i])
    
dic = defaultdict(list)

for i in range(N):
    dic[x[i]].append(i)

ans1 = -10 ** 18

for i in range(N):
    m = seg_tree.query(i, min(i+D+1, N))
    
    if (m-x[i]) * K > ans1:
        ans1 = (m - x[i]) * K
        ans2 = i
        l = dic[m]
        
        for l_i in sorted(l):
            if i <= l_i < min(i+D+1, N):
                ans3 = l_i
                break

if ans1 == 0:
    print(0)
else:
    print(ans1)
    print(ans2, ans3)
0