結果
| 問題 |
No.489 株に挑戦
|
| コンテスト | |
| ユーザー |
IL_msta
|
| 提出日時 | 2017-02-25 00:18:54 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 36 ms / 1,000 ms |
| コード長 | 2,908 bytes |
| コンパイル時間 | 2,526 ms |
| コンパイル使用メモリ | 119,884 KB |
| 実行使用メモリ | 5,632 KB |
| 最終ジャッジ日時 | 2024-07-19 23:14:43 |
| 合計ジャッジ時間 | 3,083 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 35 |
ソースコード
//以下を参考にした
//https://yukicoder.me/wiki/auto_vectorization
#ifdef __GNUC__
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#endif
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <valarray>
//#include <array>//x C++ (G++ 4.6.4)
#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>
#include <cassert>//assert();
#include <fstream>
#include <random>
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
/////////
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#define PII pair<int,int>
/////////
using namespace::std;
// 最大公約数
template<class T>
inline T gcd(T a, T b){return b ? gcd(b, a % b) : a;}
//inline T gcd(T a, T b){return b == 0 ? a : gcd(b, a % b);}
// 最小公倍数
template<class T>
inline T lcm(T a, T b){return a / gcd(a, b) * b;}
//inline T lcm(T a, T b){return a * b / gcd(a, b);}
////////////////////////////////
class segment{
int n; //nは2のべき乗
int MAX_VAL;
vector< pair<int,int> > dat;//first:val second:index
public:
int getN(){return n;}
void init(int N,int MAX_num){//N:要素数,最大値
MAX_VAL = MAX_num;
n = 2;
while(n < N ){
n <<= 1;
}
dat.assign(2*n-1,pair<int,int>(MAX_VAL,-1));
}
void update(int i,int x){
i += n-1;//葉のノード番号
dat[i] = pair<int,int>(x,i -(n-1));//値を更新,index
while(i>0){
i = (i-1)/2;
dat[i] = min( dat[i*2+1],dat[i*2+2] );
}
}
//query(a,b,0,0,n)
//[a,b)
pair<int,int> query(int a,int b,int k,int l,int r){
if(r<=a || b<=l){
return pair<int,int>(MAX_VAL,-1);//交差しない
}
if(a<=l && r<=b){
return dat[k];
}
else{
pair<int,int> vl = query(a,b,k*2+1,l,(l+r)/2);
pair<int,int> vr = query(a,b,k*2+2,(l+r)/2,r);
return min(vl,vr);
}
}
};
void solve(){
int N,D;
LL K;
cin >> N >> D >> K;
vector<int> X( N+1 );
segment segMin;
segMin.init( N,1000001);
int NN = segMin.getN();
for(int i=0;i<N;++i){
cin >> X[i];
segMin.update(i,X[i]);
}
pair<int,int> res;
int MAX = 0;
int posL = -1;
int posR = -1;
/*for(int i=0;i<=N;++i){
pair<int,int> temp = segMin.query(i,i+1,0,0,(int)NN);
cerr << temp.first << ":"<<temp.second << endl;
}*/
for(int i=0;i<N;++i){
res = segMin.query(i-D,i+1,0,0,(int)NN);
int temp = X[i]-res.first;
if( temp > MAX ){
MAX = temp;
posL = res.second;
posR = i;
}
}
if( MAX > 0 ){
cout << (LL)MAX*K << endl;
cout << posL << " " << posR << endl;
}else{
cout << 0 << endl;
}
return;
}
signed main(void){
std::cin.tie(0);
std::ios::sync_with_stdio(false);
//std::cout << std::fixed;//小数を10進数表示
//cout << setprecision(16);//小数点以下の桁数を指定
solve();
}
IL_msta