結果

問題 No.489 株に挑戦
ユーザー TwizzTwizz
提出日時 2017-06-08 20:56:23
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,370 bytes
コンパイル時間 3,067 ms
コンパイル使用メモリ 159,692 KB
実行使用メモリ 4,596 KB
最終ジャッジ日時 2023-10-23 19:54:22
合計ジャッジ時間 4,674 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include"bits/stdc++.h"

//#include<bits/stdc++.h>
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
typedef long long ll;
typedef pair<int, int> PI;
typedef pair<int, PI> V;
typedef vector<int> VE;
const ll mod = 100000000000;

//最大を求めるセグメントtree
int n, dat[2 * 100002 - 1];

void init(int n_) {
	n = 1;
	while (n < n_)n *= 2;
	REP(i, 2 * n - 1)dat[i] = -1;
}

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

int query(int a, int b, int k, int l, int r) {
	if (r <= a || b <= l)return -1;
	if (a <= l&&r <= b)return dat[k];
	else {
		int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
		int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
		return max(vr, vl);
	}
}

int main() {
	int n_, d, k;
	int x[100002];
	cin >> n_ >> d >> k;
	init(n_);
	REP(i, n_) {
		cin >> x[i];
		update(i, x[i]);
	}
	int max_ = 0;
	int sub = 0;
	int l = -1;
	int r = -1;
	REP(i, n_) {
		max_ =query(i, i + d, 0, 0, n);
		if (sub < max_ - x[i]) {
			l = i;
			sub = max_ - x[i];
			for(int j=1;i+j<=i+d;j++) {
				if (x[i + j] == max_) {
					r = i + j; break;
				}
			}
		}
	}
	ll price = sub*k;
	if (price == 0) { print(0); return 0; }
	print(price);
	cout << l <<" "<< r << endl;
	return 0;
}

0