結果

問題 No.489 株に挑戦
ユーザー ldsybldsyb
提出日時 2017-02-25 02:02:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,399 bytes
コンパイル時間 655 ms
コンパイル使用メモリ 73,900 KB
実行使用メモリ 7,220 KB
最終ジャッジ日時 2023-09-01 22:01:18
合計ジャッジ時間 3,776 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 WA -
testcase_08 AC 2 ms
4,376 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 1 ms
4,376 KB
testcase_12 WA -
testcase_13 AC 1 ms
4,380 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 43 ms
7,088 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 49 ms
7,132 KB
testcase_21 AC 12 ms
4,376 KB
testcase_22 AC 6 ms
4,376 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 45 ms
7,192 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 50 ms
7,120 KB
testcase_31 AC 53 ms
7,216 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 28 ms
5,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;

const auto compare = [](const auto& left, const auto& right){
	if(left.first >= right.first) return left;
	return right;
};

struct segtree{
	using segclass = pair<long long, long long>;
	const segclass def = make_pair(0, 0);

	int n = 1;
	vector<segclass> tree;

	segtree(int n_){
		while(n_ > (n <<= 1));
		n <<= 1;
		tree = vector<segclass>(n - 1, def);
		n >>= 1;
	}

	segclass get(int k){
		return tree[k + n - 1];
	}

	void update(int k, segclass a){
		k += n - 1;
		tree[k] = a;
		while(k > 0){
			k = (k - 1) / 2;
			tree[k] = compare(tree[2 * k + 1], tree[2 * k + 2]);
		}
	}

	segclass query(int a, int b, int k, int l, int r){
		if(r <= a || b <= l) return def;
		if(a <= l && r <= b) return tree[k];
		else{
			auto vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
			auto vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
			return compare(vl, vr);
		}
	}
};

int main(){
	int n, d, k;
	cin >> n >> d >> k;
	segtree seg(n);
	for(int i = 0, x; i < n && cin >> x; i++) seg.update(i, make_pair(x, i));
	long long num = 0;
	pair<int, int> p;
	for(int i = 0; i < n; i++){
		auto maxi = seg.query(i, min(n, i + d), 0, 0, n);
		if(num < maxi.first - seg.get(i).first){
			num = maxi.first - seg.get(i).first;
			p = make_pair(i, maxi.second);
		}
	}
	cout << num * k << endl;
	if(!num) return 0;
	cout << p.first << ' ' << p.second << endl;
}
0