結果

問題 No.489 株に挑戦
ユーザー uafr_csuafr_cs
提出日時 2017-02-24 23:07:04
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,606 bytes
コンパイル時間 2,640 ms
コンパイル使用メモリ 87,668 KB
実行使用メモリ 68,844 KB
最終ジャッジ日時 2023-08-30 23:43:49
合計ジャッジ時間 19,334 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 150 ms
56,724 KB
testcase_03 AC 150 ms
56,836 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 151 ms
56,700 KB
testcase_09 WA -
testcase_10 AC 159 ms
57,008 KB
testcase_11 AC 159 ms
57,088 KB
testcase_12 AC 161 ms
57,080 KB
testcase_13 AC 160 ms
56,844 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 149 ms
57,220 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 728 ms
65,072 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Set;

public class Main {
	
	public static class MaxSegTree{
		int n;
		long[] dat;
		int[] index;

		public MaxSegTree(int n_) {
			int n = 1;
			while(n < n_){ n *= 2; }

			this.n = n;
			dat = new long[this.n * 2 - 1];
			index = new int[this.n * 2 - 1];
			
			for(int i = 0; i < this.n * 2 - 1 ; i++){
				dat[i] = 0;
				index[i] = i;
			}
		}
		
		public void update(int k, long a){
			k += n - 1;
			dat[k] = a;
			index[k] = (k - (n - 1));

			while(k > 0){
				k = (k - 1) / 2;
				
				if(dat[k * 2 + 1] >= dat[k * 2 + 2]){
					dat[k] = dat[k * 2 + 1];
					index[k] = index[k * 2 + 1];
				}else{
					dat[k] = dat[k * 2 + 2];
					index[k] = index[k * 2 + 2];
				}
			}
		}
		
		public int query_index(int a, int b, int k, int l, int r){
			//System.out.println(a + " " + b + " " + k + " " + l + " " + r);
			if(r <= a || b <= l){ return -1; }
			if(a <= l && r <= b){ return index[k]; }
			
			final int left_index  = query_index(a, b, k * 2 + 1, l, (l + r) / 2);
			final int right_index = query_index(a, b, k * 2 + 2, (l + r) / 2, r);
			assert(left_index >= 0 || right_index >= 0);
			
			if(right_index < 0){ return left_index; }
			if(left_index < 0){ return right_index; }
			
			if(dat[left_index] >= dat[right_index]){
				return left_index;
			}else{
				return right_index;
			}
		}

		public int query_index(int a, int b){
			return query_index(a, b, 0, 0, n);
		}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		final int D = sc.nextInt();
		final int K = sc.nextInt();
		
		long[] price = new long[N];
		for(int i = 0; i < N; i++){
			price[i] = sc.nextLong();
		}
		
		MaxSegTree seg = new MaxSegTree(N);
		for(int i = 0; i < N; i++){ seg.update(i, price[i]); }
		
		long answer = Long.MIN_VALUE;
		int a_begin = -1, b_begin = -1;
		
		for(int begin = 0; begin < N; begin++){
			final int end = Math.min(N, begin + D + 1);
			
			//System.out.println(begin + " " + end);
			
			final long range_max  = price[seg.query_index(begin, end)];
			final long begin_price = price[begin];
			final long money = (range_max - begin_price) * K;
			
			if(answer < money){
				answer = money;
				a_begin = begin;
				b_begin = seg.query_index(begin, end);
			}
		}
		
		System.out.println(answer);
		System.out.println(a_begin + " " + b_begin);
	}
}
0