結果
問題 | No.489 株に挑戦 |
ユーザー |
![]() |
提出日時 | 2025-04-16 01:04:19 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,313 bytes |
コンパイル時間 | 250 ms |
コンパイル使用メモリ | 81,460 KB |
実行使用メモリ | 76,796 KB |
最終ジャッジ日時 | 2025-04-16 01:06:27 |
合計ジャッジ時間 | 3,519 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 33 WA * 2 |
ソースコード
import sys from collections import deque def main(): N, D, K = map(int, sys.stdin.readline().split()) x = [int(sys.stdin.readline()) for _ in range(N)] dq = deque() max_profit = 0 best_j = -1 best_k = -1 for k in range(1, N): window_left = max(0, k - D) # Remove elements out of the window from the front while dq and dq[0] < window_left: dq.popleft() current_j = k - 1 # Remove elements from the back that are >= current_j's x while dq and x[dq[-1]] >= x[current_j]: dq.pop() dq.append(current_j) # The front is the index of the minimum value in the current window min_j = dq[0] current_profit = x[k] - x[min_j] total_profit = current_profit * K if total_profit > max_profit: max_profit = total_profit best_j = min_j best_k = k elif total_profit == max_profit and total_profit > 0: # Check lexicographical order if (min_j < best_j) or (min_j == best_j and k < best_k): best_j = min_j best_k = k if max_profit > 0: print(max_profit) print(best_j, best_k) else: print(0) if __name__ == "__main__": main()