結果

問題 No.489 株に挑戦
ユーザー izryt(趣味)izryt(趣味)
提出日時 2017-04-05 00:11:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 68 ms / 1,000 ms
コード長 2,177 bytes
コンパイル時間 2,633 ms
コンパイル使用メモリ 173,484 KB
実行使用メモリ 9,908 KB
最終ジャッジ日時 2023-09-27 05:40:32
合計ジャッジ時間 4,172 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
9,840 KB
testcase_01 AC 31 ms
6,492 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 5 ms
4,380 KB
testcase_16 AC 52 ms
9,904 KB
testcase_17 AC 8 ms
4,380 KB
testcase_18 AC 30 ms
6,492 KB
testcase_19 AC 24 ms
6,544 KB
testcase_20 AC 57 ms
9,792 KB
testcase_21 AC 15 ms
4,576 KB
testcase_22 AC 6 ms
4,376 KB
testcase_23 AC 34 ms
6,608 KB
testcase_24 AC 65 ms
9,832 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 55 ms
9,856 KB
testcase_27 AC 68 ms
9,904 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 61 ms
9,836 KB
testcase_31 AC 61 ms
9,856 KB
testcase_32 AC 35 ms
6,484 KB
testcase_33 AC 63 ms
9,908 KB
testcase_34 AC 56 ms
9,780 KB
testcase_35 AC 24 ms
6,740 KB
testcase_36 AC 9 ms
4,380 KB
testcase_37 AC 33 ms
6,428 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define int long long

#define rep(i, x) for (int i = 0; i < x; ++i)
#define rrep(i, x) for (int i = x-1; i >= 0; --i)

using pii=pair<int,int>;

const int inf = 3e18;

struct segtree { // 区間min,max
    int n;
    vector<pii> Max;
    vector<int> Min;
    void init(int n_) {
        n = 1;
        while (n < n_) n *= 2;
        Max.resize(2 * n);
        Min.resize(2 * n);
        for (int i = 0; i < 2 * n - 1; ++i) {
            Max[i] = pii(-inf, -inf);
            Min[i] = inf;
        }
    }
    void update(int idx, int val) {
        idx += n - 1;
        Min[idx] = val;
        Max[idx] = pii(val, -(idx - n + 1));
        while (idx > 0) {
            idx = (idx - 1) / 2;
            Min[idx] = min(Min[idx * 2 + 1], Min[idx * 2 + 2]);
            Max[idx] = max(Max[idx * 2 + 1], Max[idx * 2 + 2]);
        }
    }
    int get_min(int a, int b, int k = 0, int l = 0, int r = -1) { // [a, b)のmin
        if (r == -1) r = n;
        if (r <= a || b <= l) return inf;
        if (a <= l && r <= b) return Min[k];
        int vl = get_min(a, b, k * 2 + 1, l, (l + r) / 2);
        int vr = get_min(a, b, k * 2 + 2, (l + r) / 2, r);
        return min(vl, vr);
    }
    pii get_max(int a, int b, int k = 0, int l = 0, int r = -1) { // [a, b)のmax
        if (r == -1) r = n;
        if (r <= a || b <= l) return pii(-inf, -inf);
        if (a <= l && r <= b) return Max[k];
        pii vl = get_max(a, b, k * 2 + 1, l, (l + r) / 2);
        pii vr = get_max(a, b, k * 2 + 2, (l + r) / 2, r);
        return max(vl, vr);
    }
};

int x[100010];

signed main()
{
    int N,D,K;cin>>N>>D>>K;
    segtree seg;
    seg.init(N+1);
    rep(i, N) {
        cin>>x[i];
        seg.update(i, x[i]);
    }

    int ma = -inf;
    pii hoge;

    rep(i, N) {
        int a = x[i]*K;
        pii b = seg.get_max(i, min(i + 1 + D, N));
        if (ma < b.first*K - a) {
            ma = b.first*K - a;
            hoge.first = i, hoge.second = -b.second;
        }
    }

    if (ma <= 0) {
        cout << 0 << endl;
        return 0;
    }

    cout << ma << endl;
    cout << hoge.first << ' ' << hoge.second << endl;
}
0