結果

問題 No.489 株に挑戦
ユーザー imulanimulan
提出日時 2017-02-26 03:16:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 50 ms / 1,000 ms
コード長 1,670 bytes
コンパイル時間 1,699 ms
コンパイル使用メモリ 171,152 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2023-09-27 05:28:29
合計ジャッジ時間 4,084 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
7,520 KB
testcase_01 AC 23 ms
5,340 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 40 ms
7,476 KB
testcase_17 AC 5 ms
4,376 KB
testcase_18 AC 23 ms
5,464 KB
testcase_19 AC 18 ms
5,352 KB
testcase_20 AC 40 ms
7,424 KB
testcase_21 AC 10 ms
4,380 KB
testcase_22 AC 4 ms
4,376 KB
testcase_23 AC 23 ms
5,504 KB
testcase_24 AC 46 ms
7,420 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 38 ms
7,524 KB
testcase_27 AC 50 ms
7,432 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 42 ms
7,520 KB
testcase_31 AC 45 ms
7,580 KB
testcase_32 AC 25 ms
5,500 KB
testcase_33 AC 45 ms
7,720 KB
testcase_34 AC 40 ms
7,424 KB
testcase_35 AC 17 ms
5,404 KB
testcase_36 AC 7 ms
4,380 KB
testcase_37 AC 24 ms
5,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

typedef pair<ll,int> pl;

struct MaxSegTree{
    long n; vector<pl> dat;
    //初期化
    MaxSegTree(long _n){
        n=1;
        while(n<_n) n*=2;
        dat=vector<pl>(2*n-1,pl(-1,1));
    }
    //k番目(0-indexed)の値をaに変更
    void update(long k, pl a){
        k+=n-1;
        dat[k]=a;
        //更新
        while(k>0){
            k=(k-1)/2;
            dat[k]=max(dat[2*k+1],dat[2*k+2]);
        }
    }
    //内部的に投げられるクエリ
    pl _query(long a, long b, long k, long l, long r){
        if(r<=a || b<=l) return pl(-1,1);

        if(a<=l && r<=b) return dat[k];

        pl vl=_query(a,b,2*k+1,l,(l+r)/2);
        pl vr=_query(a,b,2*k+2,(l+r)/2,r);
        return max(vl,vr);
    }
    //[a,b)の最大値を求める
    pl query(long a, long b){
        return _query(a,b,0,0,n);
    }
};

int main()
{
    int n,d;
    ll k;
    cin >>n >>d >>k;

    ll ans=0;
    int p=-1,q=-1;

    MaxSegTree st(n);
    vector<int> x(n);
    rep(i,n)
    {
        scanf(" %d", &x[i]);
        st.update(i,pl(x[i],-i));
    }

    rep(i,n)
    {
        pl res = st.query(i,min(n,i+d+1));
        ll diff = res.fi - x[i];
        diff*=k;
        if(diff>ans)
        {
            ans = diff;
            p = i;
            q = -res.se;
        }
    }




    cout << ans << endl;
    if(p!=-1) printf("%d %d\n",p,q);
    return 0;
}
0