結果

問題 No.489 株に挑戦
ユーザー playrollerplayroller
提出日時 2018-09-15 00:19:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,824 bytes
コンパイル時間 1,638 ms
コンパイル使用メモリ 172,144 KB
実行使用メモリ 5,588 KB
最終ジャッジ日時 2023-09-20 19:56:18
合計ジャッジ時間 4,506 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
5,336 KB
testcase_01 RE -
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 4 ms
4,376 KB
testcase_16 AC 33 ms
5,428 KB
testcase_17 AC 5 ms
4,504 KB
testcase_18 AC 18 ms
4,516 KB
testcase_19 AC 15 ms
4,380 KB
testcase_20 WA -
testcase_21 RE -
testcase_22 AC 5 ms
4,380 KB
testcase_23 AC 18 ms
4,420 KB
testcase_24 WA -
testcase_25 AC 2 ms
4,380 KB
testcase_26 WA -
testcase_27 AC 44 ms
5,396 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 21 ms
4,476 KB
testcase_33 WA -
testcase_34 AC 32 ms
5,300 KB
testcase_35 AC 15 ms
4,444 KB
testcase_36 RE -
testcase_37 RE -
権限があれば一括ダウンロードができます

ソースコード

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, 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