結果

問題 No.489 株に挑戦
ユーザー kentahamakentahama
提出日時 2017-03-11 23:07:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 59 ms / 1,000 ms
コード長 1,632 bytes
コンパイル時間 1,500 ms
コンパイル使用メモリ 167,568 KB
実行使用メモリ 5,640 KB
最終ジャッジ日時 2023-09-27 05:38:23
合計ジャッジ時間 3,828 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
5,240 KB
testcase_01 AC 27 ms
4,740 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 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 2 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,376 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 48 ms
5,368 KB
testcase_17 AC 7 ms
4,380 KB
testcase_18 AC 27 ms
4,452 KB
testcase_19 AC 22 ms
4,380 KB
testcase_20 AC 53 ms
5,388 KB
testcase_21 AC 13 ms
4,376 KB
testcase_22 AC 5 ms
4,380 KB
testcase_23 AC 30 ms
4,504 KB
testcase_24 AC 59 ms
5,584 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 49 ms
5,560 KB
testcase_27 AC 53 ms
5,556 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 51 ms
5,580 KB
testcase_31 AC 47 ms
5,560 KB
testcase_32 AC 31 ms
4,536 KB
testcase_33 AC 59 ms
5,532 KB
testcase_34 AC 51 ms
5,640 KB
testcase_35 AC 21 ms
4,380 KB
testcase_36 AC 8 ms
4,380 KB
testcase_37 AC 28 ms
4,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define ifnot(x) if(not(x))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

int N, D, K;
int n;
int x   [100000];
int st  [262144];
int inds[262144];

void init() {
  for (n = 1; n < N; n *= 2);
  rep(i, N) {
    st[n + i] = x[i];
    inds[n + i] = i;
  }
  rrep2(i, 1, n) {
    st[i] = max(st[i*2], st[i*2 + 1]);
    inds[i] = inds[i*2 + ((st[i*2] >= st[i*2 + 1]) ? 0 : 1)];
  }
}

P query(int a, int b, int k, int l, int r) {
  if (r <= a || b <= l) return P(0, n);
  if (a <= l && r <= b) return P(st[k], inds[k]);
  P v1 = query(a, b, k * 2    , l, (l + r) / 2);
  P v2 = query(a, b, k * 2 + 1, (l + r) / 2, r);
  return max(v1, v2, [](const P v1, const P v2) {
      if (v1.first == v2.first) return v1.second > v2.second;
      return v1.first < v2.first;
    });
}

P run_query(int a, int b) {
  return query(a, b, 1, 0, n);
}

void solve() {
  cin >> N >> D >> K;
  rep(i, N) cin >> x[i];
  init();
  int max_dif = 0, max_i = 0, max_j = 0;
  rep(i, N) {
    P res = run_query(i, i + D + 1);
    int dif = res.first - x[i];
    if (max_dif < dif) {
      max_dif = dif;
      max_i = i;
      max_j = res.second;
    }
  }
  ll wealth = (ll)K * max_dif;
  cout << wealth << endl;
  if (wealth) cout << max_i << ' ' << max_j << endl;
}

int main() {
  solve();
  return 0;
}
0