結果
問題 |
No.489 株に挑戦
|
ユーザー |
![]() |
提出日時 | 2017-02-26 16:29:34 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,175 bytes |
コンパイル時間 | 523 ms |
コンパイル使用メモリ | 66,428 KB |
実行使用メモリ | 13,264 KB |
最終ジャッジ日時 | 2024-06-11 16:43:23 |
合計ジャッジ時間 | 2,106 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 WA * 7 |
ソースコード
#include <iostream> #include <queue> using namespace std; struct Quote { Quote(long long price, int date) : price(price), date(date) {} long long price; int date; }; bool operator<(const Quote& lhs, const Quote& rhs) { if (lhs.price != rhs.price) { return lhs.price < rhs.price; } return lhs.date > rhs.date; } int main(int argc, const char * argv[]) { int n, d; long long k; cin >> n >> d >> k; long long x[1000000]; for (int i = 0; i < n; ++i) { cin >> x[i]; } priority_queue<Quote> max; for (int i = 0; i < d - 1; ++i) { max.push(Quote(x[i], i)); } long long maxProfit = 0; int maxIn = 0, maxOut = 0; for (int i = 0; i < n - d; ++i) { max.push(Quote(x[i + d], i + d)); while (max.top().date < i) { max.pop(); } long long profit = max.top().price - x[i]; if (maxProfit < profit) { maxProfit = profit; maxIn = i; maxOut = max.top().date; } } cout << (maxProfit * k) << endl; if (maxProfit > 0) { cout << maxIn << " " << maxOut << endl; } return 0; }