結果

問題 No.489 株に挑戦
ユーザー htensai
提出日時 2020-02-12 10:24:46
言語 Java
(openjdk 23)
結果
AC  
実行時間 965 ms / 1,000 ms
コード長 1,765 bytes
コンパイル時間 2,666 ms
コンパイル使用メモリ 83,684 KB
実行使用メモリ 72,952 KB
最終ジャッジ日時 2024-12-31 11:13:33
合計ジャッジ時間 22,179 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static final int MOD = 1000000007;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        long k = sc.nextInt();
        TreeSet<Stock> stocks = new TreeSet<>();
        Stock[] arr = new Stock[n];
        int max = 0;
        int left = 0;
        int right = 0;
        stocks.add(new Stock(-1, Integer.MAX_VALUE));
        for (int i = 0; i < n; i++) {
            arr[i] = new Stock(i, sc.nextInt());
            Stock target = stocks.first();
            if (max < arr[i].value - target.value) {
                max = arr[i].value - target.value;
                left = target.idx;
                right = i;
            }
            stocks.add(arr[i]);
            if (i - d >= 0) {
                stocks.remove(arr[i - d]);
            }
        }
        if (max == 0) {
            System.out.println(0);
        } else {
            System.out.println(max * k);
            System.out.println(left + " " + right);
        }
    }
    
    static class Stock implements Comparable<Stock> {
        int idx;
        int value;
        
        public Stock(int idx, int value) {
            this.idx = idx;
            this.value = value;
        }
        
        public int compareTo(Stock another) {
            if (value == another.value) {
                return idx - another.idx;
            } else {
                return value - another.value;
            }
        }
        
        public int hashCode() {
            return idx;
        }
        
        public boolean equals(Object o) {
            Stock s = (Stock)o;
            return s.idx == idx && s.value == value;
        }
    }
}
0