結果
| 問題 | 
                            No.489 株に挑戦
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2021-02-28 20:49:10 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 13 ms / 1,000 ms | 
| コード長 | 898 bytes | 
| コンパイル時間 | 1,999 ms | 
| コンパイル使用メモリ | 200,184 KB | 
| 最終ジャッジ日時 | 2025-01-19 08:19:37 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 35 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}
int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n,d; cin >> n >> d;
	ll K; cin >> K;
	vector<int> x(n);
	for(int i=0;i<n;i++){
		cin >> x[i];
	}
	deque<pair<int,int>> dq;
	ll res=0;
	int rj=0,rk=0;
	for(int i=0;i<n;i++){
		while(dq.size() and dq.front().second<i-d)dq.pop_front();
		if(dq.size()){
			int c=x[i]-dq.front().first;
			if(c>res){
				res=c;
				rj=dq.front().second;
				rk=i;
			}
			else if(c==res){
				int j=dq.front().second;
				if(rj>j){
					rj=j; rk=i;
				}
			}
		}
		while(dq.size() and dq.back().first>x[i])dq.pop_back();
		dq.push_back(make_pair(x[i],i));
	}
	res*=K;
	printf("%lld\n",res);
	if(res>0)printf("%d %d\n",rj,rk);
}