結果

問題 No.489 株に挑戦
ユーザー beetbeet
提出日時 2017-02-24 22:43:31
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 108 ms / 1,000 ms
コード長 1,234 bytes
コンパイル時間 1,399 ms
コンパイル使用メモリ 167,688 KB
実行使用メモリ 16,724 KB
最終ジャッジ日時 2023-09-27 04:59:46
合計ジャッジ時間 4,150 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
13,876 KB
testcase_01 AC 46 ms
9,776 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 5 ms
4,376 KB
testcase_16 AC 58 ms
8,012 KB
testcase_17 AC 10 ms
4,376 KB
testcase_18 AC 35 ms
6,236 KB
testcase_19 AC 27 ms
5,664 KB
testcase_20 AC 93 ms
15,200 KB
testcase_21 AC 20 ms
5,972 KB
testcase_22 AC 8 ms
4,380 KB
testcase_23 AC 52 ms
10,120 KB
testcase_24 AC 108 ms
16,496 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 80 ms
16,724 KB
testcase_27 AC 51 ms
6,928 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,384 KB
testcase_30 AC 103 ms
16,260 KB
testcase_31 AC 78 ms
16,724 KB
testcase_32 AC 53 ms
10,244 KB
testcase_33 AC 100 ms
15,724 KB
testcase_34 AC 89 ms
14,368 KB
testcase_35 AC 31 ms
8,072 KB
testcase_36 AC 13 ms
4,928 KB
testcase_37 AC 51 ms
10,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long
struct RMQ{
  int n;
  vector<int> dat;
  const int def=0;
  RMQ(){}
  RMQ(int n_){init(n_);}
  void init(int n_){
    n=1;
    while(n<n_) n*=2;
    dat.clear();
    dat.resize(2*n-1,def);
  }
  void update(int k,int a){
    k+=n-1;
    dat[k]=a;
    while(k>0){
      k=(k-1)/2;
      dat[k]=max(dat[k*2+1],dat[k*2+2]);
    }
  }
  int query(int a,int b,int k,int l,int r){
    if(r<=a||b<=l) return def;
    if(a<=l&&r<=b) return dat[k];
    else{
      int vl=query(a,b,k*2+1,l,(l+r)/2);
      int vr=query(a,b,k*2+2,(l+r)/2,r);
      return max(vl,vr);
    }
  }
  int query(int a,int b){
    return query(a,b,0,0,n);
  }
};
signed main(){
  int n,d,k;
  cin>>n>>d>>k;
  int ans=0,idx=0,idy=0;
  RMQ rmq(n);
  map<int,vector<int> > m;
  int a[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
    m[a[i]].push_back(i);
    rmq.update(i,a[i]);
  }
  for(int i=0;i<n;i++){
    int p=min(i+d+1,n);
    int x=rmq.query(i,p);
    if(ans<x-a[i]){
      ans=x-a[i];
      idx=i;
    }
  }
  cout<<ans*k<<endl;
  int p=min(idx+d+1,n);
  int x=rmq.query(idx,p);
  vector<int> v=m[x];
  idy=*upper_bound(v.begin(),v.end(),idx);
  if(ans) cout<<idx<<" "<<idy<<endl;
  return 0;
}
0