結果

問題 No.489 株に挑戦
ユーザー data9824data9824
提出日時 2017-02-26 16:29:34
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,175 bytes
コンパイル時間 494 ms
コンパイル使用メモリ 65,624 KB
実行使用メモリ 7,700 KB
最終ジャッジ日時 2023-09-02 10:00:58
合計ジャッジ時間 2,533 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
5,668 KB
testcase_01 WA -
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 26 ms
5,880 KB
testcase_17 AC 6 ms
4,380 KB
testcase_18 AC 15 ms
4,804 KB
testcase_19 WA -
testcase_20 AC 32 ms
5,808 KB
testcase_21 AC 9 ms
4,380 KB
testcase_22 AC 5 ms
4,380 KB
testcase_23 AC 20 ms
4,460 KB
testcase_24 WA -
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 32 ms
7,700 KB
testcase_27 AC 35 ms
5,708 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 WA -
testcase_31 AC 34 ms
6,048 KB
testcase_32 AC 20 ms
4,576 KB
testcase_33 AC 34 ms
5,812 KB
testcase_34 WA -
testcase_35 AC 13 ms
4,376 KB
testcase_36 AC 6 ms
4,376 KB
testcase_37 AC 20 ms
4,468 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0