結果

問題 No.489 株に挑戦
ユーザー htensaihtensai
提出日時 2020-02-12 10:24:46
言語 Java21
(openjdk 21)
結果
AC  
実行時間 883 ms / 1,000 ms
コード長 1,765 bytes
コンパイル時間 2,288 ms
コンパイル使用メモリ 77,364 KB
実行使用メモリ 71,820 KB
最終ジャッジ日時 2023-09-27 06:09:32
合計ジャッジ時間 21,401 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 662 ms
62,968 KB
testcase_01 AC 613 ms
63,172 KB
testcase_02 AC 154 ms
57,304 KB
testcase_03 AC 157 ms
56,864 KB
testcase_04 AC 127 ms
55,720 KB
testcase_05 AC 159 ms
56,964 KB
testcase_06 AC 167 ms
56,924 KB
testcase_07 AC 165 ms
56,868 KB
testcase_08 AC 153 ms
56,520 KB
testcase_09 AC 168 ms
56,880 KB
testcase_10 AC 168 ms
57,096 KB
testcase_11 AC 170 ms
56,752 KB
testcase_12 AC 168 ms
56,956 KB
testcase_13 AC 168 ms
57,036 KB
testcase_14 AC 169 ms
56,992 KB
testcase_15 AC 281 ms
60,856 KB
testcase_16 AC 825 ms
69,232 KB
testcase_17 AC 333 ms
61,220 KB
testcase_18 AC 585 ms
63,508 KB
testcase_19 AC 550 ms
62,936 KB
testcase_20 AC 812 ms
69,052 KB
testcase_21 AC 439 ms
60,836 KB
testcase_22 AC 311 ms
61,728 KB
testcase_23 AC 542 ms
61,056 KB
testcase_24 AC 883 ms
70,828 KB
testcase_25 AC 137 ms
56,176 KB
testcase_26 AC 663 ms
69,424 KB
testcase_27 AC 717 ms
66,804 KB
testcase_28 AC 156 ms
56,764 KB
testcase_29 AC 126 ms
56,044 KB
testcase_30 AC 859 ms
71,820 KB
testcase_31 AC 661 ms
70,524 KB
testcase_32 AC 591 ms
63,704 KB
testcase_33 AC 865 ms
70,944 KB
testcase_34 AC 774 ms
69,684 KB
testcase_35 AC 505 ms
60,956 KB
testcase_36 AC 370 ms
61,448 KB
testcase_37 AC 603 ms
63,496 KB
権限があれば一括ダウンロードができます

ソースコード

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