結果

問題 No.489 株に挑戦
ユーザー TatsunoTatsuno
提出日時 2017-02-25 02:24:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 60 ms / 1,000 ms
コード長 2,347 bytes
コンパイル時間 1,691 ms
コンパイル使用メモリ 173,164 KB
実行使用メモリ 7,268 KB
最終ジャッジ日時 2023-09-27 05:18:48
合計ジャッジ時間 3,685 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
7,248 KB
testcase_01 AC 28 ms
5,112 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 4 ms
4,376 KB
testcase_16 AC 49 ms
7,200 KB
testcase_17 AC 7 ms
4,376 KB
testcase_18 AC 28 ms
5,096 KB
testcase_19 AC 22 ms
5,168 KB
testcase_20 AC 52 ms
7,160 KB
testcase_21 AC 12 ms
4,380 KB
testcase_22 AC 5 ms
4,376 KB
testcase_23 AC 30 ms
5,204 KB
testcase_24 AC 60 ms
7,192 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 51 ms
7,268 KB
testcase_27 AC 58 ms
7,208 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 55 ms
7,208 KB
testcase_31 AC 57 ms
7,260 KB
testcase_32 AC 31 ms
5,156 KB
testcase_33 AC 59 ms
7,200 KB
testcase_34 AC 52 ms
7,148 KB
testcase_35 AC 22 ms
5,244 KB
testcase_36 AC 8 ms
4,376 KB
testcase_37 AC 30 ms
5,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <bits/stdc++.h>
using namespace std;
using i32 = int; using i64 = long long int; using f64 = double; using str = string;
template <typename T> using vec = vector<T>;
template <typename T> using heap = priority_queue<T, vec<T>, greater<T>>;
#define times(n, i) for (i32 i = 0; i < (n); ++i)
#define range(a, b, i) for (i32 i = (a); i < (b); ++i)
#define upto(a, b, i) for (i32 i = (a); i <= (b); ++i)
#define downto(a, b, i) for (i32 i = (a); i >= (b); --i)
#define all(xs) (xs).begin(), (xs).end()
#define sortall(xs) sort(all(xs))
#define reverseall(xs) reverse(all(xs))
#define uniqueall(xs) (xs).erase(unique(all(xs)), (xs).end())
#define even(x) (((x) & 1) == 0)
#define odd(x) (((x) & 1) == 1)
#define append emplace_back
const i64 MOD = 1000000007;

i32 n, d, k;

template <typename T, typename Cmp> struct segtree {
    i32 n; T defval; vec<T> data;
    segtree(i32 size, T default_value) : defval(default_value) { n=1; while(n<size) n*=2; data.resize(2*n-1, defval); }
    void update(i32 i, T x) {
        i += n-1; data[i] = x;
        while (i > 0) {
            i = (i-1)/2;
            data[i] = Cmp()(data[i*2+1], data[i*2+2]) ? data[i*2+1] : data[i*2+2];
        }
    }
    T query(i32 l, i32 r) {
        return _query(l, r, 0, 0, n);
    }
    T _query(i32 a, i32 b, i32 k, i32 l, i32 r) {
        if (r <= a || b <= l) return defval;
        if (a <= l && r <= b) return data[k];
        else {
            T vl = _query(a, b, k*2+1, l, (l+r)/2);
            T vr = _query(a, b, k*2+2, (l+r)/2, r);
            return Cmp()(vl, vr) ? vl : vr;
        }
    }
    T leaf(i32 i) { return data[i+n-1]; }
};

i32 main()
{
    cin >> n >> d >> k;
    using P = pair<i64, i32>;
    auto seg = segtree<P, greater<P>>(n, make_pair(-1, 1));
    i32 jj = 0, kk = 0; i64 dd = 0;
    times(n, i) {
        i32 x; cin >> x;
        seg.update(i, make_pair(x, -i));
    }
    times(n, i) {
        P x = seg.leaf(i);
        P maxx = seg.query(min(n-1, i+1), min(n, i+d+1));
        if (maxx.first - x.first > dd) {
            dd = maxx.first - x.first;
            jj = i;
            kk = -maxx.second;
        }
    }

    if (dd == 0) {
        cout << 0 << endl;
    } else {
        cout << dd*k << endl;
        cout << jj << " " << kk << endl;
    }
    return 0;
}
0