結果

問題 No.489 株に挑戦
ユーザー tomatoma
提出日時 2019-09-24 23:36:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 49 ms / 1,000 ms
コード長 1,694 bytes
コンパイル時間 1,585 ms
コンパイル使用メモリ 171,964 KB
実行使用メモリ 8,900 KB
最終ジャッジ日時 2023-09-27 06:05:05
合計ジャッジ時間 3,906 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
8,192 KB
testcase_01 AC 25 ms
5,940 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,500 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 38 ms
8,524 KB
testcase_17 AC 5 ms
4,380 KB
testcase_18 AC 22 ms
5,952 KB
testcase_19 AC 18 ms
5,668 KB
testcase_20 AC 44 ms
8,628 KB
testcase_21 AC 12 ms
4,424 KB
testcase_22 AC 5 ms
4,376 KB
testcase_23 AC 24 ms
6,008 KB
testcase_24 AC 49 ms
8,844 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 44 ms
8,720 KB
testcase_27 AC 44 ms
8,768 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 47 ms
8,724 KB
testcase_31 AC 44 ms
8,900 KB
testcase_32 AC 27 ms
5,940 KB
testcase_33 AC 47 ms
8,648 KB
testcase_34 AC 41 ms
8,520 KB
testcase_35 AC 18 ms
5,696 KB
testcase_36 AC 8 ms
4,380 KB
testcase_37 AC 26 ms
6,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
using pll = pair<ll, ll>;

template<typename T>
class SegmentTree {
private:
	using F = function<T(T, T)>; // モノイド型
	int n; // 横幅
	F f;   // モノイド
	T e;   // モノイド単位元
	vector<T> data;

public:
	// init忘れに注意
	SegmentTree() {}
	SegmentTree(F f, T e) :f(f), e(e) {}
	void init(int n_) {
		n = 1;
		while (n < n_)n <<= 1;
		data.assign(n << 1, e);
	}
	void build(const vector<T>& v) {
		int n_ = v.size();
		init(n_);
		rep(i, n_)data[n + i] = v[i];
		for (int i = n - 1; i >= 0; i--) {
			data[i] = f(data[(i << 1) | 0], data[(i << 1) | 1]);
		}
	}
	void set_val(int idx, T val) {
		idx += n;
		data[idx] = val;
		while (idx >>= 1) {
			data[idx] = f(data[(idx << 1) | 0], data[(idx << 1) | 1]);
		}
	}
	T query(int a, int b) {
		// [a,b)
		T vl = e, vr = e;
		for (int l = a + n, r = b + n; l < r; l >>= 1, r >>= 1) {
			if (l & 1)vl = f(vl, data[l++]); // unknown
			if (r & 1)vr = f(data[--r], vr); // unknown
		}
		return f(vl, vr);
	}
};

int main()
{
	ll N, D, K;
	cin >> N >> D >> K;
	vector<pll>x(N);
	rep(i, N) {
		ll buf;
		cin >> buf;
		x[i] = { buf,-i };
	}

	auto f = [](pll a, pll b) {return max(a, b); };
	SegmentTree<pll> seg(f, { -1ll << 60,-1 });
	seg.build(x);

	ll score = 0, buy = -1, sell = -1;
	rep(tbuy, N) {
		auto high = seg.query(tbuy, min(tbuy + D + 1, N));
		ll gain = high.first - x[tbuy].first;
		if (gain > score) {
			score = gain;
			buy = tbuy;
			sell = -high.second;
		}
	}
	cout << score * K << endl;
	if (score != 0)cout << buy << " " << sell << endl;
	return 0;
}
0