結果

問題 No.489 株に挑戦
ユーザー femtofemto
提出日時 2017-02-25 00:32:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 39 ms / 1,000 ms
コード長 1,528 bytes
コンパイル時間 1,600 ms
コンパイル使用メモリ 168,648 KB
実行使用メモリ 8,728 KB
最終ジャッジ日時 2023-09-27 05:17:12
合計ジャッジ時間 3,816 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
8,496 KB
testcase_01 AC 19 ms
8,016 KB
testcase_02 AC 4 ms
7,528 KB
testcase_03 AC 4 ms
7,436 KB
testcase_04 AC 4 ms
7,516 KB
testcase_05 AC 4 ms
7,484 KB
testcase_06 AC 4 ms
7,500 KB
testcase_07 AC 4 ms
7,432 KB
testcase_08 AC 4 ms
7,496 KB
testcase_09 AC 4 ms
7,492 KB
testcase_10 AC 4 ms
7,448 KB
testcase_11 AC 4 ms
7,624 KB
testcase_12 AC 4 ms
7,540 KB
testcase_13 AC 4 ms
7,660 KB
testcase_14 AC 4 ms
7,620 KB
testcase_15 AC 5 ms
7,820 KB
testcase_16 AC 31 ms
8,452 KB
testcase_17 AC 7 ms
7,780 KB
testcase_18 AC 20 ms
8,044 KB
testcase_19 AC 16 ms
7,896 KB
testcase_20 AC 32 ms
8,516 KB
testcase_21 AC 10 ms
7,752 KB
testcase_22 AC 6 ms
7,572 KB
testcase_23 AC 21 ms
8,112 KB
testcase_24 AC 39 ms
8,648 KB
testcase_25 AC 4 ms
7,432 KB
testcase_26 AC 36 ms
8,660 KB
testcase_27 AC 36 ms
8,624 KB
testcase_28 AC 3 ms
7,532 KB
testcase_29 AC 4 ms
7,480 KB
testcase_30 AC 33 ms
8,656 KB
testcase_31 AC 29 ms
8,728 KB
testcase_32 AC 23 ms
8,104 KB
testcase_33 AC 37 ms
8,604 KB
testcase_34 AC 34 ms
8,640 KB
testcase_35 AC 16 ms
7,876 KB
testcase_36 AC 8 ms
7,656 KB
testcase_37 AC 19 ms
8,132 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int MAX_N = 1 << 17;
const int def = 1 << 25;
const int INF = 1 << 25;

typedef pair<ll, int> Node;
struct MinSegTreeIdx {
	int n;
	Node node[2 * MAX_N - 1];
	int minIdx[2 * MAX_N - 1];

	void init(int n_) {
		n = 1;
		while(n < n_) n *= 2;
		for(int i = 0; i < 2 * n - 1; i++) node[i] = make_pair(def, INF);
	}

	Node merge(Node l, Node r) {
		if(l.first <= r.first) return l;
		return r;
	}

	void update(int k, ll a) {
		k += n - 1;
		node[k] = make_pair(a, k - (n - 1));
		minIdx[k] = k - (n - 1);
		while(k > 0) {
			k = (k - 1) / 2;
			node[k] = merge(node[k * 2 + 1], node[k * 2 + 2]);
		}
	}

	Node query(int a, int b) { return query(a, b, 0, 0, n); }

	Node query(int a, int b, int k, int l, int r) {
		if(r <= a || b <= l) return make_pair(def, INF);
		if(a <= l && r <= b) return node[k];
		Node vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
		Node vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
		return merge(vl, vr);
	}
};

MinSegTreeIdx st;
ll x[100000];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N, D;
	ll K;
	cin >> N >> D >> K;

	st.init(N);
	for(int i = 0; i < N; i++) {
		cin >> x[i];
		st.update(i, x[i]);
	}

	ll ans = 0, ansj = -1, ansk = -1;
	for(int i = 0; i < N; i++) {
		Node res = st.query(max(i - D, 0), i + 1);
		if((x[i] - res.first) * K > ans) {
			ans = (x[i] - res.first) * K;
			ansj = i;
			ansk = res.second;
		}
	}

	cout << ans << endl;
	if(ans != 0) {
		cout << ansk << " " << ansj << endl;
	}
}
0