結果

問題 No.489 株に挑戦
ユーザー hornistyfhornistyf
提出日時 2020-01-06 23:19:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 54 ms / 1,000 ms
コード長 1,469 bytes
コンパイル時間 660 ms
コンパイル使用メモリ 93,124 KB
実行使用メモリ 9,636 KB
最終ジャッジ日時 2023-09-27 06:06:48
合計ジャッジ時間 3,034 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
9,464 KB
testcase_01 AC 28 ms
7,452 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 43 ms
9,520 KB
testcase_17 AC 5 ms
4,380 KB
testcase_18 AC 24 ms
7,420 KB
testcase_19 AC 21 ms
7,560 KB
testcase_20 AC 47 ms
9,468 KB
testcase_21 AC 12 ms
4,376 KB
testcase_22 AC 5 ms
4,380 KB
testcase_23 AC 28 ms
7,732 KB
testcase_24 AC 53 ms
9,568 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 44 ms
9,544 KB
testcase_27 AC 48 ms
9,636 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 47 ms
9,464 KB
testcase_31 AC 46 ms
9,552 KB
testcase_32 AC 31 ms
7,440 KB
testcase_33 AC 54 ms
9,460 KB
testcase_34 AC 46 ms
9,492 KB
testcase_35 AC 21 ms
7,452 KB
testcase_36 AC 8 ms
4,376 KB
testcase_37 AC 27 ms
7,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//yuki489.cpp
//Mon Jan  6 22:44:48 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;

ll nodenum;
P seg[400000];

void init(ll n){
	nodenum = 1;
	while (nodenum < n){
		nodenum*=2;
	}
	for (int i=0;i<nodenum*2-1;i++){
		seg[i] = make_pair(0,-1);
	}
}

P query(ll a, ll b, ll k, ll l, ll r){
	if (r<=a || b<=l){
		return make_pair(0,-1);
	}
	if (a<=l && r<=b){
		return seg[k];
	}else {
		P v1 = query(a,b,k*2+1,l,(l+r)/2);
		P v2 = query(a,b,k*2+2,(l+r)/2,r);
		if (v1.first>=v2.first){
			return v1;
		}else {
			return v2;
		}
	}
}

int main(){
	ll n,d,k;
	cin >> n >> d >> k;

	init(n);

	for (ll i=0;i<n;i++){
		ll temp;
		cin >> temp;
		seg[nodenum-1+i] = make_pair(temp,i);
	}

	for (ll i=nodenum-2;i>=0;i--){
		if (seg[2*i+1].first>=seg[2*i+2].first){
			seg[i] = seg[2*i+1];
		}else {
			seg[i] = seg[2*i+2];
		}
	}

	P ans = make_pair(0,-1);
	ll ansindex = -1;
	for (ll i=0;i<n;i++){
		ll last = min(i+d,n-1);
		P temp = query(i,i+d+1,0,0,nodenum);
		ll x = temp.first-seg[nodenum-1+i].first;
		if (ans.first<x){
			ans.first = x;
			ans.second = temp.second;
			ansindex = i;
		}
	}

	cout << ans.first*k << endl;
	if (ansindex>=0){
		cout << ansindex << " " << ans.second << endl;
	}
//	printf("%.4f\n",ans);
}
0