結果

問題 No.489 株に挑戦
ユーザー roarisroaris
提出日時 2019-08-09 19:23:55
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,423 bytes
コンパイル時間 848 ms
コンパイル使用メモリ 87,316 KB
実行使用メモリ 106,804 KB
最終ジャッジ日時 2023-09-26 13:20:45
合計ジャッジ時間 23,161 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 773 ms
99,600 KB
testcase_01 AC 704 ms
90,840 KB
testcase_02 AC 96 ms
71,648 KB
testcase_03 AC 97 ms
71,828 KB
testcase_04 AC 97 ms
71,664 KB
testcase_05 AC 98 ms
71,636 KB
testcase_06 AC 105 ms
72,268 KB
testcase_07 AC 102 ms
72,356 KB
testcase_08 AC 98 ms
71,812 KB
testcase_09 AC 106 ms
76,912 KB
testcase_10 AC 104 ms
76,872 KB
testcase_11 AC 106 ms
76,356 KB
testcase_12 AC 107 ms
76,816 KB
testcase_13 AC 105 ms
77,140 KB
testcase_14 AC 106 ms
76,732 KB
testcase_15 AC 238 ms
80,336 KB
testcase_16 TLE -
testcase_17 AC 301 ms
82,276 KB
testcase_18 AC 757 ms
85,216 KB
testcase_19 AC 721 ms
85,884 KB
testcase_20 TLE -
testcase_21 AC 457 ms
85,788 KB
testcase_22 AC 285 ms
82,572 KB
testcase_23 AC 613 ms
93,476 KB
testcase_24 TLE -
testcase_25 AC 108 ms
76,712 KB
testcase_26 TLE -
testcase_27 TLE -
testcase_28 AC 96 ms
71,940 KB
testcase_29 AC 96 ms
71,668 KB
testcase_30 TLE -
testcase_31 AC 963 ms
106,804 KB
testcase_32 AC 824 ms
94,332 KB
testcase_33 TLE -
testcase_34 TLE -
testcase_35 AC 662 ms
88,684 KB
testcase_36 AC 356 ms
82,864 KB
testcase_37 AC 756 ms
92,736 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]) <= ans1:
        continue
    else:
        ans1 = m - x[i]
        ans2 = i
        
        for l_i in dic[m]:
            if i <= l_i:
                ans3 = l_i
                break
    
if ans1 == 0:
    print(0)
else:
    print(ans1 * K)
    print(ans2, ans3)
0