結果

問題 No.489 株に挑戦
ユーザー oxyshoweroxyshower
提出日時 2019-08-15 20:56:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 61 ms / 1,000 ms
コード長 1,758 bytes
コンパイル時間 1,604 ms
コンパイル使用メモリ 174,776 KB
実行使用メモリ 10,672 KB
最終ジャッジ日時 2023-09-27 06:02:06
合計ジャッジ時間 3,668 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
9,312 KB
testcase_01 AC 26 ms
6,464 KB
testcase_02 AC 1 ms
4,384 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,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 44 ms
9,768 KB
testcase_17 AC 7 ms
4,376 KB
testcase_18 AC 27 ms
6,424 KB
testcase_19 AC 20 ms
6,272 KB
testcase_20 AC 49 ms
9,828 KB
testcase_21 AC 12 ms
4,564 KB
testcase_22 AC 6 ms
4,376 KB
testcase_23 AC 31 ms
6,724 KB
testcase_24 AC 61 ms
10,308 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 50 ms
10,360 KB
testcase_27 AC 60 ms
10,356 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 50 ms
10,672 KB
testcase_31 AC 44 ms
10,496 KB
testcase_32 AC 33 ms
6,680 KB
testcase_33 AC 55 ms
10,104 KB
testcase_34 AC 53 ms
9,780 KB
testcase_35 AC 21 ms
6,212 KB
testcase_36 AC 8 ms
4,376 KB
testcase_37 AC 27 ms
6,860 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif

template <class T>
struct SegmentTree{
  using F = function<T(T,T)>;
  F f;
  T inf;
  int n;
  vector<T> node;

  SegmentTree(vector<T> v,T inf,F f):inf(inf),f(f){
    n = 1; while(n < v.size()) n *= 2;
    node.resize(2*n-1,inf);
    for(int i = 0; i < v.size(); i++) node[i+n-1] = v[i];
    for(int i = n-2; i >= 0; i--) node[i] = f(node[2*i+1],node[2*i+2]);
  }

  void update(int k,T val){
    k += n-1;
    node[k] = val;
    while(k > 0){
      k = (k-1) / 2;
      node[k] = f(node[2*k+1],node[2*k+2]);
    }
  }

  void add(int k,T val){
    k += n-1;
    node[k] += val;
    while(k > 0){
      k = (k-1) / 2;
      node[k] = f(node[2*k+1],node[2*k+2]);
    }
  }

  T getval(int a,int b){ return getval(a,b,0,0,n); }
  T getval(int a,int b,int k,int l,int r){
    //区間[a, b)の値を返す
    if(r <= a || b <= l) return inf;
    if(a <= l && r <= b) return node[k];
    T vl = getval(a, b, 2*k+1, l, (l+r)/2);
    T vr = getval(a, b, 2*k+2, (l+r)/2, r);
    return f(vl, vr);
  }
};

using P = pair<int,int>;
const P INF = {1<<30,1<<30};

signed main(){

  int n,d,k; cin >> n >> d >> k;
  vector<P> x(n);
  for(int i = 0; i < n; i++){
    int a; cin >> a;
    x[i] = {a,i};
  }

  SegmentTree<P> seg(x,INF,[&](P x,P y){
    return min(x,y);
  });
  P ans = {-1<<30,-1<<30};
  int l = 0;
  for(int i = 1; i < n; i++){
    P res = seg.getval(max(0LL,i-d),i+1);
    int j = x[i].first - res.first;
    if(ans.first < j){
      ans = {j,res.second};
      l = i;
    }
  }
  if(ans.first <= 0) cout << 0 << endl;
  else {
    cout << ans.first * k << endl;
    cout << ans.second << " " << l << endl;
  }

  return 0;
}
0