結果

問題 No.489 株に挑戦
ユーザー iqueue02iqueue02
提出日時 2019-12-23 21:29:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,443 bytes
コンパイル時間 1,784 ms
コンパイル使用メモリ 173,872 KB
実行使用メモリ 5,740 KB
最終ジャッジ日時 2023-10-19 04:23:08
合計ジャッジ時間 3,899 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
5,740 KB
testcase_01 WA -
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 4 ms
4,348 KB
testcase_16 AC 44 ms
5,740 KB
testcase_17 AC 8 ms
4,348 KB
testcase_18 AC 31 ms
4,684 KB
testcase_19 WA -
testcase_20 AC 49 ms
5,740 KB
testcase_21 AC 11 ms
4,348 KB
testcase_22 AC 7 ms
4,348 KB
testcase_23 AC 36 ms
4,684 KB
testcase_24 WA -
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 38 ms
5,740 KB
testcase_27 AC 70 ms
5,740 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 WA -
testcase_31 AC 35 ms
5,740 KB
testcase_32 AC 38 ms
4,684 KB
testcase_33 AC 58 ms
5,740 KB
testcase_34 WA -
testcase_35 AC 22 ms
4,536 KB
testcase_36 AC 8 ms
4,348 KB
testcase_37 AC 26 ms
4,684 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;

template <typename T> 
struct SegmentTree {
  
  int n;
  vector<T> node;

  T f(T a, T b) {return max(a, b);}

  SegmentTree (int sz, T init = 0) {
    n = 1; while (n < sz) n <<= 1;
    node.assign(2*n, init);
  }

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

  T query(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    if (r <= a || b <= l) return 0;
    if (a <= l && r <= b) return node[k];
    T vl = query(a, b, 2*k+1, l, (l+r)/2);
    T vr = query(a, b, 2*k+2, (l+r)/2, r);
    return f(vl, vr);
  }

  T getvalue(int k) {
    return query(k,k+1);
  }

};

int main(){
  int n, d, k;
  cin >> n >> d >> k;
  SegmentTree<ll> seg(n);
  vector<int> x(n);
  rep(i,n) {
    cin >> x[i];
    seg.update(i,x[i]);
  }
  ll res = 0;
  int midx = -1;
  for (int i = 0; i + d < n; i++) {
    ll dif = seg.query(i,i+d+1);
    ll v = dif - seg.getvalue(i);
    if (res < v) {
      res = v;
      midx = i;
    }
  }
  cout << res * k << endl;
  if (res > 0) {
    for (int i = 0; i <= d; i++) {
      if (x[midx + i] - x[midx] == res) {
        cout << midx << " " << i + midx << endl;
        return 0;
      }
    }
  }
  return 0;
}
0