結果

問題 No.489 株に挑戦
ユーザー nanaenanae
提出日時 2017-02-24 23:38:41
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,539 bytes
コンパイル時間 191 ms
コンパイル使用メモリ 10,948 KB
実行使用メモリ 24,416 KB
最終ジャッジ日時 2023-08-31 00:12:19
合計ジャッジ時間 3,514 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 16 ms
8,368 KB
testcase_03 AC 16 ms
8,448 KB
testcase_04 AC 16 ms
8,296 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 16 ms
8,316 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 16 ms
8,300 KB
testcase_26 AC 82 ms
17,508 KB
testcase_27 WA -
testcase_28 AC 16 ms
8,456 KB
testcase_29 AC 16 ms
8,296 KB
testcase_30 WA -
testcase_31 AC 81 ms
17,056 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from itertools import accumulate

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def solve():
    N, D, K = map(int, input().split())
    X = [int(sys.stdin.readline().rstrip()) for i in range(N)]
    Xac = list(accumulate(X))
    mims = []
    maxs = []

    for i in range(N):
        if i == 0:
            if X[0] < X[1]:
                mims.append((i, X[i]))
        elif i == N - 1:
            if X[-1] > X[-2]:
                maxs.append((i, X[i]))
        else:
            if X[i - 1] < X[i] and X[i] >= X[i + 1]:
                maxs.append((i, X[i]))
            elif X[i - 1] >= X[i] and X[i] < X[i + 1]:
                mims.append((i, X[i]))

    max_dif = 0
    j, k = None, None

    for p1, p2 in zip(mims, maxs):
        if p2[0] - p1[0] <= D:
            if p2[1] - p1[1] > max_dif:
                max_dif = p2[1] - p1[1]
                j, k = p1[0], p2[0]
        else:
            j1, k1, dif = find_maxdif(Xac, p1[0], p2[0], D)
            if dif > max_dif:
                j, k = j1, k1
                max_dif = dif

    if max_dif <= 0:
        print(0)
    else:
        print(max_dif * K)
        print(j, k)

def find_maxdif(Xac, l, r, D):
    res = 0
    j, k = 0, 0

    for i in range(l, r + 1 - D):
        if Xac[i + D] - Xac[i] > res:
            res = Xac[i + D] - Xac[i]
            j, k = i, i + D

    return j, k, res

if __name__ == '__main__':
    solve()
0