結果

問題 No.489 株に挑戦
ユーザー mogurockermogurocker
提出日時 2017-10-25 02:03:25
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 92 ms / 1,000 ms
コード長 1,517 bytes
コンパイル時間 1,473 ms
コンパイル使用メモリ 154,700 KB
実行使用メモリ 69,120 KB
最終ジャッジ日時 2023-09-27 05:50:20
合計ジャッジ時間 5,067 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
69,044 KB
testcase_01 AC 63 ms
68,832 KB
testcase_02 AC 41 ms
68,412 KB
testcase_03 AC 41 ms
68,408 KB
testcase_04 AC 40 ms
68,468 KB
testcase_05 AC 39 ms
68,516 KB
testcase_06 AC 39 ms
68,472 KB
testcase_07 AC 38 ms
68,508 KB
testcase_08 AC 39 ms
68,284 KB
testcase_09 AC 38 ms
68,296 KB
testcase_10 AC 38 ms
68,524 KB
testcase_11 AC 38 ms
68,408 KB
testcase_12 AC 38 ms
68,288 KB
testcase_13 AC 39 ms
68,528 KB
testcase_14 AC 39 ms
68,476 KB
testcase_15 AC 40 ms
68,620 KB
testcase_16 AC 77 ms
68,988 KB
testcase_17 AC 45 ms
68,288 KB
testcase_18 AC 61 ms
68,732 KB
testcase_19 AC 55 ms
68,900 KB
testcase_20 AC 78 ms
69,112 KB
testcase_21 AC 48 ms
68,768 KB
testcase_22 AC 43 ms
68,288 KB
testcase_23 AC 64 ms
68,852 KB
testcase_24 AC 84 ms
68,988 KB
testcase_25 AC 39 ms
68,288 KB
testcase_26 AC 82 ms
69,088 KB
testcase_27 AC 92 ms
68,984 KB
testcase_28 AC 40 ms
68,456 KB
testcase_29 AC 40 ms
68,408 KB
testcase_30 AC 80 ms
69,104 KB
testcase_31 AC 77 ms
69,120 KB
testcase_32 AC 65 ms
68,780 KB
testcase_33 AC 87 ms
69,088 KB
testcase_34 AC 79 ms
68,724 KB
testcase_35 AC 54 ms
68,844 KB
testcase_36 AC 44 ms
68,908 KB
testcase_37 AC 60 ms
68,720 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define FORR(x, arr) for(auto& x:arr)
#define ITR(x, c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;
typedef pair<int, int> P;

int n, d, k;

template<class V,int NV> class SegTree_Pair {
public:
	vector<pair<V,int> > val;
	static V const def=1<<22;
	pair<V,int> comp(pair<V,int> l,pair<V,int> r){ return min(l,r);}
	SegTree_Pair(){
		val.resize(NV*2);
		int i;
		FOR(i,NV) val[i+NV]=make_pair(def,i);
		for(i=NV-1;i>=1;i--) val[i]=comp(val[2*i],val[2*i+1]);
	};
	pair<V,int> getval(int x,int y,int l=0,int r=NV,int k=1) {
		if(r<=x || y<=l) return make_pair(def,NV);
		if(x<=l && r<=y) return val[k];
		return comp(getval(x,y,l,(l+r)/2,k*2),getval(x,y,(l+r)/2,r,k*2+1));
	}
	void update(int entry, V v) {
		entry += NV;
		val[entry]=make_pair(v,entry-NV);
		while(entry>1) entry>>=1, val[entry]=comp(val[entry*2],val[entry*2+1]);
	}
};
SegTree_Pair<int,1<<22> st;

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> n >> d >> k;
	vector<int> x(n);
	FOR(i, n) {
		cin >> x[i];
		st.update(i, x[i]);
	}
	int ma = 0, l, r;
	FOR(i, n) {
		P p = st.getval(max(i-d,0), i);
		if (ma < x[i]-p.first) {
			ma = x[i]-p.first;
			r = i;
			l = p.second;
		}
	}

	cout << 1LL*ma*k << endl;
	if (ma > 0) cout << l << " " << r << endl;
	return 0;
}
0