結果

問題 No.489 株に挑戦
ユーザー tentententen
提出日時 2023-01-30 19:48:55
言語 Java21
(openjdk 21)
結果
AC  
実行時間 304 ms / 1,000 ms
コード長 2,663 bytes
コンパイル時間 5,579 ms
コンパイル使用メモリ 85,788 KB
実行使用メモリ 61,372 KB
最終ジャッジ日時 2023-09-12 17:17:57
合計ジャッジ時間 11,918 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 253 ms
59,180 KB
testcase_01 AC 225 ms
60,752 KB
testcase_02 AC 80 ms
52,716 KB
testcase_03 AC 80 ms
52,580 KB
testcase_04 AC 45 ms
49,612 KB
testcase_05 AC 79 ms
52,580 KB
testcase_06 AC 79 ms
52,568 KB
testcase_07 AC 81 ms
52,584 KB
testcase_08 AC 78 ms
53,664 KB
testcase_09 AC 81 ms
52,512 KB
testcase_10 AC 83 ms
53,756 KB
testcase_11 AC 80 ms
52,592 KB
testcase_12 AC 83 ms
53,656 KB
testcase_13 AC 83 ms
52,720 KB
testcase_14 AC 82 ms
51,468 KB
testcase_15 AC 149 ms
54,716 KB
testcase_16 AC 254 ms
60,748 KB
testcase_17 AC 186 ms
56,872 KB
testcase_18 AC 214 ms
59,080 KB
testcase_19 AC 205 ms
59,184 KB
testcase_20 AC 267 ms
61,372 KB
testcase_21 AC 188 ms
58,328 KB
testcase_22 AC 152 ms
54,940 KB
testcase_23 AC 237 ms
59,364 KB
testcase_24 AC 274 ms
60,700 KB
testcase_25 AC 47 ms
49,572 KB
testcase_26 AC 231 ms
60,204 KB
testcase_27 AC 304 ms
58,632 KB
testcase_28 AC 81 ms
52,912 KB
testcase_29 AC 45 ms
49,764 KB
testcase_30 AC 274 ms
61,132 KB
testcase_31 AC 250 ms
60,424 KB
testcase_32 AC 233 ms
59,436 KB
testcase_33 AC 272 ms
60,960 KB
testcase_34 AC 264 ms
60,840 KB
testcase_35 AC 208 ms
59,196 KB
testcase_36 AC 161 ms
56,284 KB
testcase_37 AC 225 ms
59,064 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int d = sc.nextInt();
        long k = sc.nextInt();
        PriorityQueue<Stock> queue = new PriorityQueue<>();
        queue.add(new Stock(0, sc.nextInt()));
        int max = 0;
        int left = 0;
        int right = 0;
        for (int i = 1; i < n; i++) {
            int x = sc.nextInt();
            while (i - queue.peek().day > d) {
                queue.poll();
            }
            int diff = x - queue.peek().amount;
            if (max < diff) {
                max = diff;
                left = queue.peek().day;
                right = i;
            }
            queue.add(new Stock(i, x));
        }
        System.out.println(max * k);
        if (max > 0) {
            System.out.println(left + " " + right);
        }
    }
    
    static class Stock implements Comparable<Stock> {
        int day;
        int amount;
        
        public Stock(int day, int amount) {
            this.day = day;
            this.amount = amount;
        }
        
        public int compareTo(Stock another) {
            if (amount == another.amount) {
                return day - another.day;
            } else {
                return amount - another.amount;
            }
        }
    }
}

class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0