結果

問題 No.489 株に挑戦
ユーザー tookunn_1213tookunn_1213
提出日時 2017-02-27 22:21:56
言語 Java21
(openjdk 21)
結果
AC  
実行時間 346 ms / 1,000 ms
コード長 3,273 bytes
コンパイル時間 4,474 ms
コンパイル使用メモリ 76,788 KB
実行使用メモリ 66,072 KB
最終ジャッジ日時 2023-09-27 05:32:11
合計ジャッジ時間 11,215 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 291 ms
65,924 KB
testcase_01 AC 250 ms
59,804 KB
testcase_02 AC 76 ms
52,408 KB
testcase_03 AC 75 ms
50,716 KB
testcase_04 AC 43 ms
49,228 KB
testcase_05 AC 74 ms
50,560 KB
testcase_06 AC 77 ms
52,064 KB
testcase_07 AC 78 ms
52,072 KB
testcase_08 AC 73 ms
50,528 KB
testcase_09 AC 76 ms
50,940 KB
testcase_10 AC 75 ms
50,616 KB
testcase_11 AC 73 ms
50,544 KB
testcase_12 AC 75 ms
50,436 KB
testcase_13 AC 74 ms
51,408 KB
testcase_14 AC 76 ms
50,880 KB
testcase_15 AC 130 ms
56,064 KB
testcase_16 AC 320 ms
65,860 KB
testcase_17 AC 160 ms
56,920 KB
testcase_18 AC 239 ms
59,268 KB
testcase_19 AC 219 ms
61,744 KB
testcase_20 AC 300 ms
65,716 KB
testcase_21 AC 212 ms
61,144 KB
testcase_22 AC 151 ms
57,568 KB
testcase_23 AC 246 ms
59,904 KB
testcase_24 AC 346 ms
65,696 KB
testcase_25 AC 45 ms
49,440 KB
testcase_26 AC 289 ms
65,136 KB
testcase_27 AC 308 ms
65,748 KB
testcase_28 AC 76 ms
52,160 KB
testcase_29 AC 42 ms
49,152 KB
testcase_30 AC 321 ms
65,628 KB
testcase_31 AC 306 ms
65,620 KB
testcase_32 AC 260 ms
59,696 KB
testcase_33 AC 311 ms
65,772 KB
testcase_34 AC 299 ms
66,072 KB
testcase_35 AC 222 ms
62,404 KB
testcase_36 AC 182 ms
58,048 KB
testcase_37 AC 257 ms
59,732 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main{
	int N,D,K;
	int[] x;

	static final int INF = -((int)1e9+7);
	P[] segment;
	int size;

	private class P{
		int i,v;
		public P(int i,int v){
			this.i = i;
			this.v = v;
		}
	}

	public void segInit(int N){
		size = 1;
		while(size < N){
			size <<= 1;
		}

		segment = new P[size*2];
		for(int i = 0;i < size * 2;i++){
			segment[i] = new P(INF,INF);
		}
	}

	public void segUpdate(int i,int a){
		P tmp = new P(i,a);
		i = size + i - 1;
		segment[i] = tmp;

		while(i > 0){
			i = (i-1)>>1;
			int i1 = i*2+1;
			int i2 = i*2+2;
			if (segment[i1].v < segment[i2].v){
				segment[i] = segment[i2];
			}else if (segment[i1].v > segment[i2].v){
				segment[i] = segment[i1];
			}else if(segment[i1].i <= segment[i2].i){
				segment[i] = segment[i1];
			}else{
				segment[i] = segment[i2];
			}
		}
	}

	public P segQuery(int a,int b,int k,int l,int r){
		if(r <= a || b <= l)return new P(INF,INF);
		if(a <= l && r <= b)return segment[k];

		P left = segQuery(a,b,2*k+1,l,(l+r)/2);
		P right = segQuery(a,b,2*k+2,(l+r)/2,r);

		if (left.v == INF && right.v == INF)return new P(INF,INF);
		if(left.v == INF)return right;
		if(right.v == INF)return left;
		if(left.v < right.v)return right;
		if(left.v > right.v)return left;
		if(left.i <= right.i)return left;
		else return right;
	}

	public void solve() {
		N = nextInt();
		D = nextInt();
		K = nextInt();
		x = new int[N];
		for(int i = 0;i < N;i++){
			x[i] = nextInt();
		}

		segInit(N);
		for(int i = 0;i < N;i++){
			segUpdate(i,x[i]);
		}

		long ans = INF;
		int[] pair = {INF,INF};
		for(int i = 0;i < N - 1;i++){
			P ret = segQuery(i+1,Math.min(N, i+D+1),0,0,size);
			if (ans < ret.v-x[i]){
				ans = ret.v-x[i];
				pair[0] = i;
				pair[1] = ret.i;
			}
		}

		if(ans <= 0){
			out.println(0);
		}else{
			out.println(ans*K);
			out.println(pair[0] + " " + pair[1]);
		}
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}
0