結果

問題 No.489 株に挑戦
コンテスト
ユーザー vjudge1
提出日時 2025-01-29 12:23:27
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 8 ms / 1,000 ms
コード長 527 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,146 ms
コンパイル使用メモリ 209,124 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-06-26 04:35:00
合計ジャッジ時間 3,139 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
using namespace std;
int x[100005],q[100005];
int main(){
	int n,d,k;
	scanf("%d%d%d",&n,&d,&k);
	for(int i=0;i<n;++i)scanf("%d",&x[i]);
	int hd=1,tl=0;
	long long ans=0;
	int u=0,v=0;
	for(int i=n-1;i>=0;--i){
		while(hd<=tl&&q[hd]>i+d)++hd;
		while(hd<=tl&&x[q[tl]]<=x[i])--tl;
		q[++tl]=i;
		if(hd<=tl){
			long long an=1ll*(x[q[hd]]-x[i])*k;
			if(ans<=an){
				ans=an;
				u=i,v=q[hd];
			}
		}
	}
	if(ans==0){
		puts("0");
		return 0;
	}
	printf("%lld\n",ans);
	printf("%d %d\n",u,v);
	return 0;
}
0