結果

問題 No.489 株に挑戦
ユーザー DAyamaCTFDAyamaCTF
提出日時 2017-02-24 23:51:15
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 44 ms / 1,000 ms
コード長 2,000 bytes
コンパイル時間 2,509 ms
コンパイル使用メモリ 174,636 KB
実行使用メモリ 5,404 KB
最終ジャッジ日時 2023-09-27 05:13:12
合計ジャッジ時間 4,291 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
4,988 KB
testcase_01 AC 21 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 37 ms
5,404 KB
testcase_17 AC 6 ms
4,376 KB
testcase_18 AC 21 ms
4,412 KB
testcase_19 AC 17 ms
4,380 KB
testcase_20 AC 39 ms
5,092 KB
testcase_21 AC 10 ms
4,376 KB
testcase_22 AC 4 ms
4,380 KB
testcase_23 AC 22 ms
4,376 KB
testcase_24 AC 44 ms
5,220 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 39 ms
5,260 KB
testcase_27 AC 43 ms
5,268 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 40 ms
5,220 KB
testcase_31 AC 39 ms
5,176 KB
testcase_32 AC 23 ms
4,412 KB
testcase_33 AC 43 ms
5,156 KB
testcase_34 AC 37 ms
5,136 KB
testcase_35 AC 15 ms
4,380 KB
testcase_36 AC 6 ms
4,384 KB
testcase_37 AC 23 ms
4,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3
#define MAX_N (1<<18)

struct RangeMinQuery{
	int idx[2*MAX_N-1];
	int dat[MAX_N];
	int size;

	void update(int k){
		k+=size-1;
		idx[k]=k-(size-1);
		while(k>0){
			k=(k-1)/2;
			if(idx[k*2+1]!=-1&&idx[k*2+2]!=-1){
				if(dat[idx[k*2+1]]<=dat[idx[k*2+2]])idx[k]=idx[k*2+1];
				else idx[k]=idx[k*2+2];
			}else{
				idx[k]=max(idx[k*2+1],idx[k*2+2]);
			}
		}
	}

	void init(int *a,int n_){
		size=1;
		while(size<n_) size*=2;
		for(int i=0;i<2*size-1;i++)idx[i]=-1;
		for(int i=0;i<n_;i++)dat[i]=a[i];
		for(int i=0;i<n_;i++)update(i);
	}

	int subquery(int a,int b,int k,int l,int r){
		if(r<=a||b<=l)return -1;
		if(a<=l&&r<=b)return idx[k];
		else{
			int ldx=subquery(a,b,k*2+1,l,(l+r)/2),rdx=subquery(a,b,k*2+2,(l+r)/2,r);
			if(ldx!=-1&&rdx!=-1){
				if(dat[ldx]<=dat[rdx])return ldx;
				else return rdx;
			}else{
				return max(ldx,rdx);
			}
		}
	}

	int query(int a,int b){
		return subquery(a,b,0,0,size);
	}
};

ll n,d,K;
int a[111111];
RangeMinQuery s;

signed main(){
	cin.sync_with_stdio(false);
	cin>>n>>d>>K;
	rep(i,n){
		cin>>a[i];
		a[i]=-a[i];
	}
	s.init(a,n);
	ll res=0;
	ll j,k;
	rep(i,n){
		int idx=s.query(i+1,min(n,i+d+1));
		if(idx>=0&&res<-a[idx]+a[i]){
			res=-a[idx]+a[i];
			j=i;
			k=idx;
		}
	}
	cout<<res*K<<endl;
	if(res>0)cout<<j<<" "<<k<<endl;
	return 0;
}
0