結果

問題 No.489 株に挑戦
ユーザー simansiman
提出日時 2022-11-11 12:34:10
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 37 ms / 1,000 ms
コード長 1,154 bytes
コンパイル時間 2,590 ms
コンパイル使用メモリ 106,796 KB
実行使用メモリ 6,004 KB
最終ジャッジ日時 2023-10-11 09:29:32
合計ジャッジ時間 3,679 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
5,784 KB
testcase_01 AC 18 ms
4,588 KB
testcase_02 AC 2 ms
4,356 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 1 ms
4,352 KB
testcase_08 AC 1 ms
4,352 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 2 ms
4,352 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 2 ms
4,352 KB
testcase_14 AC 2 ms
4,352 KB
testcase_15 AC 4 ms
4,352 KB
testcase_16 AC 26 ms
5,872 KB
testcase_17 AC 6 ms
4,348 KB
testcase_18 AC 15 ms
4,532 KB
testcase_19 AC 13 ms
4,408 KB
testcase_20 AC 31 ms
5,888 KB
testcase_21 AC 9 ms
4,352 KB
testcase_22 AC 4 ms
4,348 KB
testcase_23 AC 21 ms
4,560 KB
testcase_24 AC 36 ms
5,936 KB
testcase_25 AC 2 ms
4,352 KB
testcase_26 AC 37 ms
6,004 KB
testcase_27 AC 37 ms
4,412 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,352 KB
testcase_30 AC 36 ms
5,988 KB
testcase_31 AC 30 ms
5,932 KB
testcase_32 AC 19 ms
4,564 KB
testcase_33 AC 34 ms
5,940 KB
testcase_34 AC 29 ms
5,852 KB
testcase_35 AC 14 ms
4,416 KB
testcase_36 AC 6 ms
4,352 KB
testcase_37 AC 20 ms
4,564 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

struct Node {
  int day;
  ll x;

  Node(int day = -1, ll x = -1) {
    this->day = day;
    this->x = x;
  }

  bool operator>(const Node &n) const {
    if (x == n.x) {
      return day > n.day;
    } else {
      return x > n.x;
    }
  }
};

int main() {
  ll N, D, K;
  cin >> N >> D >> K;

  priority_queue <Node, vector<Node>, greater<Node>> pque;
  ll X[N];
  for (int i = 0; i < N; ++i) {
    cin >> X[i];
  }
  pque.push(Node(0, X[0]));
  ll ans = 0;
  int j = -1;
  int k = -1;

  for (int day = 1; day <= N - 1; ++day) {
    ll x = X[day];

    while (day - pque.top().day > D) {
      pque.pop();
    }

    ll diff = x - pque.top().x;
    if (ans < diff * K) {
      ans = diff * K;
      j = pque.top().day;
      k = day;
    }

    pque.push(Node(day, x));
  }

  if (ans == 0) {
    cout << 0 << endl;
  } else {
    cout << ans << endl;
    cout << j << " " << k << endl;
  }

  return 0;
}
0