結果

問題 No.489 株に挑戦
コンテスト
ユーザー siman
提出日時 2022-11-11 12:32:08
言語 C++17(clang)
(clang++ 22.1.2 + boost 1.89.0)
コンパイル:
clang++ -O2 -lm -std=c++1z -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,087 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 6,147 ms
コンパイル使用メモリ 150,016 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-04-04 04:16:23
合計ジャッジ時間 3,625 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge5_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34 WA * 1
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:35:8: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   35 |   ll X[N];
      |        ^
main.cpp:35:8: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:31:6: note: declared here
   31 |   ll N, D, K;
      |      ^
1 warning generated.

ソースコード

diff #
raw source code

#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 {
    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