結果

問題 No.489 株に挑戦
ユーザー furafura
提出日時 2020-07-27 12:47:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 823 bytes
コンパイル時間 2,094 ms
コンパイル使用メモリ 203,872 KB
実行使用メモリ 4,920 KB
最終ジャッジ日時 2023-09-27 06:15:30
合計ジャッジ時間 3,559 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
4,376 KB
testcase_01 WA -
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 11 ms
4,376 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 6 ms
4,376 KB
testcase_19 AC 5 ms
4,376 KB
testcase_20 AC 11 ms
4,612 KB
testcase_21 AC 3 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 8 ms
4,380 KB
testcase_24 AC 14 ms
4,628 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 12 ms
4,628 KB
testcase_27 AC 13 ms
4,640 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 13 ms
4,920 KB
testcase_31 AC 13 ms
4,708 KB
testcase_32 AC 8 ms
4,376 KB
testcase_33 AC 14 ms
4,700 KB
testcase_34 AC 12 ms
4,428 KB
testcase_35 AC 6 ms
4,380 KB
testcase_36 AC 3 ms
4,376 KB
testcase_37 AC 8 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

template<class T>
vector<int> sliding_window_minimum(const vector<T>& a,int w){
	int n=a.size();
	if(w>n) return {};

	vector<int> res(n-w+1);
	deque<int> D;
	rep(i,n){
		while(!D.empty() && a[D.front()]>a[i]) D.pop_back();
		D.emplace_back(i);
		if(i>=w-1){
			if(i-D.front()>=w) D.pop_front();
			res[i-w+1]=D.front();
		}
	}
	return res;
}

int main(){
	int n,d,k; scanf("%d%d%d",&n,&d,&k);
	vector<int> a(2*n);
	rep(i,n) scanf("%d",&a[i]), a[i]*=-1;

	auto idx=sliding_window_minimum(a,d);

	lint ans=0;
	int l,r;
	rep(i,n){
		lint buy=-a[i],sell=-a[idx[i+1]];
		if(ans<k*(sell-buy)){
			ans=k*(sell-buy);
			l=i;
			r=idx[i+1];
		}
	}

	printf("%lld\n",ans);
	if(ans>0) printf("%d %d\n",l,r);

	return 0;
}
0