結果

問題 No.489 株に挑戦
ユーザー tnakao0123tnakao0123
提出日時 2017-02-25 21:48:23
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 54 ms / 1,000 ms
コード長 2,340 bytes
コンパイル時間 584 ms
コンパイル使用メモリ 88,676 KB
実行使用メモリ 5,744 KB
最終ジャッジ日時 2023-09-27 05:22:14
合計ジャッジ時間 2,820 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
5,528 KB
testcase_01 AC 29 ms
5,640 KB
testcase_02 AC 3 ms
5,504 KB
testcase_03 AC 3 ms
5,528 KB
testcase_04 AC 2 ms
5,380 KB
testcase_05 AC 2 ms
5,508 KB
testcase_06 AC 3 ms
5,496 KB
testcase_07 AC 3 ms
5,504 KB
testcase_08 AC 3 ms
5,528 KB
testcase_09 AC 3 ms
5,544 KB
testcase_10 AC 3 ms
5,536 KB
testcase_11 AC 3 ms
5,588 KB
testcase_12 AC 3 ms
5,508 KB
testcase_13 AC 2 ms
5,656 KB
testcase_14 AC 3 ms
5,588 KB
testcase_15 AC 4 ms
5,504 KB
testcase_16 AC 43 ms
5,580 KB
testcase_17 AC 6 ms
5,724 KB
testcase_18 AC 25 ms
5,576 KB
testcase_19 AC 21 ms
5,524 KB
testcase_20 AC 49 ms
5,532 KB
testcase_21 AC 13 ms
5,596 KB
testcase_22 AC 6 ms
5,496 KB
testcase_23 AC 27 ms
5,572 KB
testcase_24 AC 54 ms
5,520 KB
testcase_25 AC 3 ms
5,456 KB
testcase_26 AC 46 ms
5,408 KB
testcase_27 AC 49 ms
5,588 KB
testcase_28 AC 2 ms
5,588 KB
testcase_29 AC 3 ms
5,464 KB
testcase_30 AC 47 ms
5,524 KB
testcase_31 AC 46 ms
5,588 KB
testcase_32 AC 31 ms
5,572 KB
testcase_33 AC 53 ms
5,540 KB
testcase_34 AC 46 ms
5,512 KB
testcase_35 AC 20 ms
5,508 KB
testcase_36 AC 8 ms
5,744 KB
testcase_37 AC 26 ms
5,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 489.cc: No.489 株に挑戦 - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const int MAX_E2 = 1 << 18; // 262144
const int INF = 1 << 30;

/* typedef */

typedef long long ll;

struct Val {
  int v, i;
  Val() {}
  Val(int _v, int _i): v(_v), i(_i) {}
  bool operator<(const Val &a) const {
    return v < a.v || (v == a.v && i > a.i);
  }
  bool operator>(const Val &a) const {
    return v > a.v || (v == a.v && i < a.i);
  }
};

template <typename T, const int MAX_E2>
struct SegTreeMax {
  int n, e2;
  T nodes[MAX_E2], initv;
  SegTreeMax() {}

  void init(int _n, T _initv) {
    n = _n;
    initv = _initv;
    for (e2 = 1; e2 < n; e2 <<= 1);
    fill(nodes, nodes + MAX_E2, initv);
  }

  T get(int i) { return nodes[e2 - 1 + i]; }
  void set(int i, T v) { nodes[e2 - 1 + i] = v; }

  void set_all() {
    for (int j = e2 - 2; j >= 0; j--) {
      int j0 = j * 2 + 1, j1 = j0 + 1;
      nodes[j] = max(nodes[j * 2 + 1], nodes[j * 2 + 2]);
    }
  }

  T max_range(int r0, int r1, int k, int i0, int i1) {
    if (r1 <= i0 || i1 <= r0) return initv;
    if (r0 <= i0 && i1 <= r1) return nodes[k];

    int im = (i0 + i1) / 2;
    T v0 = max_range(r0, r1, k * 2 + 1, i0, im);
    T v1 = max_range(r0, r1, k * 2 + 2, im, i1);

    return max(v0, v1);
  }

  T max_range(int r0, int r1) {
    return max_range(r0, r1, 0, 0, e2);
  }
};

/* global variables */

SegTreeMax<Val,MAX_E2> stm;

/* subroutines */

/* main */

int main() {
  int n, d, k;
  cin >> n >> d >> k;

  stm.init(n, Val(0, -1));

  for (int i = 0; i < n; i++) {
    int xi;
    cin >> xi;
    stm.set(i, Val(xi, i));
  }
  stm.set_all();

  int maxx = 0, mini = -1, minj = -1;
  for (int i = 0; i < n; i++) {
    Val v = stm.max_range(i + 1, i + 1 + d);
    int x = v.v - stm.get(i).v;
    if (maxx < x)
      maxx = x, mini = i, minj = v.i;
  }

  //printf("%d %d %d\n", maxx, mini, minj);
  if (maxx <= 0) puts("0");
  else printf("%lld\n%d %d\n", (ll)maxx * k, mini, minj);
  return 0;
}
0