結果

問題 No.489 株に挑戦
ユーザー treeonetreeone
提出日時 2017-03-02 14:56:54
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 64 ms / 1,000 ms
コード長 2,132 bytes
コンパイル時間 1,323 ms
コンパイル使用メモリ 154,968 KB
実行使用メモリ 8,336 KB
最終ジャッジ日時 2023-09-27 05:34:50
合計ジャッジ時間 3,712 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
8,252 KB
testcase_01 AC 32 ms
5,468 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 4 ms
4,376 KB
testcase_16 AC 52 ms
8,004 KB
testcase_17 AC 8 ms
4,380 KB
testcase_18 AC 29 ms
5,460 KB
testcase_19 AC 23 ms
5,356 KB
testcase_20 AC 57 ms
8,004 KB
testcase_21 AC 14 ms
4,380 KB
testcase_22 AC 7 ms
4,380 KB
testcase_23 AC 33 ms
5,676 KB
testcase_24 AC 64 ms
8,248 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 54 ms
8,120 KB
testcase_27 AC 59 ms
8,076 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 60 ms
7,840 KB
testcase_31 AC 61 ms
7,928 KB
testcase_32 AC 35 ms
5,760 KB
testcase_33 AC 60 ms
8,188 KB
testcase_34 AC 56 ms
8,336 KB
testcase_35 AC 23 ms
5,624 KB
testcase_36 AC 9 ms
4,376 KB
testcase_37 AC 33 ms
5,420 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

const int INF = 1e9;

struct Segtree{
    int n;
    vector<P> dat;
    Segtree(){}
    Segtree(int _n){
        n = 1;
        while(n < _n) n *= 2;
        dat.clear();
        rep(i, 0, 2 * n){
            dat. push_back(P(-1, i));
        }
    }
    void update(int k, int a){
        dat[k + n - 1].fi = a;
        dat[k + n - 1].se = k;
        k += n - 1;        
        while(k > 0){
            k = (k - 1) / 2;
            int l = 2 * k + 1, r = 2 * k + 2;
            int MAX = -1, id = -1; 
            if(dat[l].fi < dat[r].fi){
                MAX = dat[r].fi; id = dat[r].se;
            }else{
                MAX = dat[l].fi; id = dat[l].se;
            }
            dat[k].fi = MAX; dat[k].se = id;
        }
    }
    // min[a, b)
    P query(int a, int b){
        return query(a, b, 0, 0, n);
    }
    P query(int a, int b, int k, int l, int r){
        if(r <= a || b <= l) return P(0, -1);
        if(a <= l && r <= b) return dat[k];
        else{
            int mid = (l + r) / 2;
            P vl = query(a, b, 2 * k + 1, l, mid);
            P vr = query(a, b,  2 * k + 2, mid, r);
            return (vl.fi < vr.fi ? vr : vl);
            // return max(query(a, b, 2 * k + 1, l, mid), query(a, b,  2 * k + 2, mid, r));
        }
    }
};

signed main(){
    int n, d, k;
    cin >> n >> d >> k;
    Segtree sg(n);
    vector<int> x(n);
    rep(i, 0, n){
        cin >> x[i];
        sg.update(i, x[i]);
    }
    int ans = -1, idl, idr;
    rep(i, 0, n){
        P p = sg.query(i + 1, min(n, i + d + 1));
        int tmp = p.fi - x[i];
        // cout << i << " " << p.fi <<" " << p.se << endl;
        if(tmp > ans){
            ans = tmp; idl = i; idr = p.se;
        }
    }
    if(ans <= 0) cout << 0 << endl;
    else{
        cout << ans * k << endl;
        cout << idl << " " << idr << endl;
    }
}
0