結果

問題 No.489 株に挑戦
ユーザー playrollerplayroller
提出日時 2018-09-15 00:22:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 37 ms / 1,000 ms
コード長 1,832 bytes
コンパイル時間 1,584 ms
コンパイル使用メモリ 172,216 KB
実行使用メモリ 5,468 KB
最終ジャッジ日時 2023-09-27 05:57:53
合計ジャッジ時間 3,551 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
5,396 KB
testcase_01 AC 17 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 29 ms
5,408 KB
testcase_17 AC 4 ms
4,380 KB
testcase_18 AC 17 ms
4,496 KB
testcase_19 AC 14 ms
4,400 KB
testcase_20 AC 30 ms
5,348 KB
testcase_21 AC 8 ms
4,380 KB
testcase_22 AC 4 ms
4,380 KB
testcase_23 AC 16 ms
4,412 KB
testcase_24 AC 36 ms
5,360 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 29 ms
5,356 KB
testcase_27 AC 37 ms
5,464 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,384 KB
testcase_30 AC 35 ms
5,396 KB
testcase_31 AC 36 ms
5,428 KB
testcase_32 AC 17 ms
4,396 KB
testcase_33 AC 35 ms
5,352 KB
testcase_34 AC 31 ms
5,468 KB
testcase_35 AC 12 ms
4,376 KB
testcase_36 AC 5 ms
4,376 KB
testcase_37 AC 19 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define erep(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
const int mod = 1e9+7;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pi;
typedef long long i64;

template <class Monoid> struct SegmentTree {
  using F = function<Monoid(Monoid, Monoid)>;

  int sz;
  vector<Monoid> seg;

  const F f;
  const Monoid M1;

  SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
    sz = 1;
    while(sz < n) sz <<= 1;
    seg.assign(2 * sz, M1);
  }

  void set(int k, const Monoid &x) {
    seg[k + sz] = x;
  }

  void build() {
    for(int k = sz - 1; k > 0; --k) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  void update(int k, const Monoid &x) {
    k += sz;
    seg[k] = x;
    while(k >>= 1){
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  Monoid query(int a, int b) {
    Monoid L = M1, R = M1;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) L = f(L, seg[a++]);
      if(b & 1) R = f(seg[--b], R);
    }
    return f(L, R);
  }

  Monoid operator[] (const int &k) const {
    return seg[k + sz];
  }
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n, d, k;
  cin >> n >> d >> k;

  SegmentTree<pi> seg(n, [](pi a, pi b){return max(a, b);}, make_pair(0, 0));
  vi x(n);

  rep(i, 0, n) {
    cin >> x[i];
    seg.update(i, make_pair(x[i], -i));
  }

  i64 ans = 0;
  int a = -1, b = -1;
  rep(i, 0, n) {
    auto v = seg.query(i, min(n, i + d) + 1);
    if(ans < v.first - x[i]) {
      ans = v.first - x[i];
      a = i;
      b = -v.second;
    } 
  }
  cout << ans * k << endl;
  if(ans > 0) cout << a << " " << b << endl;
}
0