結果

問題 No.489 株に挑戦
ユーザー IL_mstaIL_msta
提出日時 2017-02-25 00:18:54
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 45 ms / 1,000 ms
コード長 2,908 bytes
コンパイル時間 1,504 ms
コンパイル使用メモリ 120,328 KB
実行使用メモリ 5,512 KB
最終ジャッジ日時 2023-09-27 05:14:56
合計ジャッジ時間 3,692 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
5,460 KB
testcase_01 AC 18 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 4 ms
4,376 KB
testcase_16 AC 32 ms
5,444 KB
testcase_17 AC 5 ms
4,376 KB
testcase_18 AC 20 ms
4,412 KB
testcase_19 AC 15 ms
4,408 KB
testcase_20 AC 32 ms
5,340 KB
testcase_21 AC 8 ms
4,376 KB
testcase_22 AC 4 ms
4,380 KB
testcase_23 AC 21 ms
4,376 KB
testcase_24 AC 39 ms
5,512 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 37 ms
5,412 KB
testcase_27 AC 45 ms
5,368 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 31 ms
5,340 KB
testcase_31 AC 27 ms
5,452 KB
testcase_32 AC 22 ms
4,376 KB
testcase_33 AC 38 ms
5,428 KB
testcase_34 AC 35 ms
5,468 KB
testcase_35 AC 14 ms
4,380 KB
testcase_36 AC 5 ms
4,380 KB
testcase_37 AC 18 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//以下を参考にした
//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();
}
0