結果
問題 | No.489 株に挑戦 |
ユーザー |
![]() |
提出日時 | 2025-03-20 20:36:32 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,415 bytes |
コンパイル時間 | 151 ms |
コンパイル使用メモリ | 82,492 KB |
実行使用メモリ | 95,764 KB |
最終ジャッジ日時 | 2025-03-20 20:37:39 |
合計ジャッジ時間 | 4,095 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 33 WA * 2 |
ソースコード
from collections import deque def main(): import sys input = sys.stdin.read().split() ptr = 0 N = int(input[ptr]); ptr +=1 D = int(input[ptr]); ptr +=1 K = int(input[ptr]); ptr +=1 x = [] for _ in range(N): x.append(int(input[ptr])) ptr +=1 max_profit = 0 best_j = -1 best_k = -1 dq = deque() for k in range(N): # Remove elements out of the window [k-D, k] while dq and dq[0] < (k - D): dq.popleft() # Add current element to deque, maintaining increasing order of x[j] while dq and x[dq[-1]] >= x[k]: dq.pop() dq.append(k) current_min_j = dq[0] current_profit = K * (x[k] - x[current_min_j]) # Update max_profit and best_j, best_k if necessary if current_profit > max_profit: max_profit = current_profit best_j = current_min_j best_k = k elif current_profit == max_profit and max_profit > 0: # Check if current pair is lexicographically smaller if (current_min_j < best_j) or (current_min_j == best_j and k < best_k): best_j = current_min_j best_k = k if max_profit <= 0: print(0) else: print(max_profit) print(f"{best_j} {best_k}") if __name__ == '__main__': main()