結果
問題 | No.489 株に挑戦 |
ユーザー | tenten |
提出日時 | 2021-11-12 08:35:33 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 413 ms / 1,000 ms |
コード長 | 2,641 bytes |
コンパイル時間 | 3,120 ms |
コンパイル使用メモリ | 80,376 KB |
実行使用メモリ | 53,160 KB |
最終ジャッジ日時 | 2024-11-24 14:21:03 |
合計ジャッジ時間 | 11,571 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 322 ms
48,976 KB |
testcase_01 | AC | 292 ms
50,012 KB |
testcase_02 | AC | 84 ms
38,552 KB |
testcase_03 | AC | 88 ms
38,048 KB |
testcase_04 | AC | 50 ms
36,960 KB |
testcase_05 | AC | 75 ms
38,576 KB |
testcase_06 | AC | 84 ms
38,004 KB |
testcase_07 | AC | 79 ms
39,192 KB |
testcase_08 | AC | 80 ms
38,252 KB |
testcase_09 | AC | 77 ms
38,244 KB |
testcase_10 | AC | 77 ms
37,916 KB |
testcase_11 | AC | 80 ms
38,076 KB |
testcase_12 | AC | 80 ms
38,136 KB |
testcase_13 | AC | 80 ms
38,072 KB |
testcase_14 | AC | 77 ms
38,376 KB |
testcase_15 | AC | 175 ms
42,712 KB |
testcase_16 | AC | 377 ms
52,580 KB |
testcase_17 | AC | 180 ms
42,956 KB |
testcase_18 | AC | 263 ms
48,660 KB |
testcase_19 | AC | 250 ms
47,896 KB |
testcase_20 | AC | 386 ms
51,924 KB |
testcase_21 | AC | 248 ms
47,788 KB |
testcase_22 | AC | 185 ms
42,312 KB |
testcase_23 | AC | 261 ms
48,612 KB |
testcase_24 | AC | 413 ms
52,764 KB |
testcase_25 | AC | 53 ms
37,224 KB |
testcase_26 | AC | 274 ms
52,528 KB |
testcase_27 | AC | 337 ms
50,328 KB |
testcase_28 | AC | 73 ms
37,916 KB |
testcase_29 | AC | 50 ms
36,948 KB |
testcase_30 | AC | 352 ms
53,160 KB |
testcase_31 | AC | 307 ms
53,104 KB |
testcase_32 | AC | 280 ms
48,548 KB |
testcase_33 | AC | 403 ms
52,940 KB |
testcase_34 | AC | 362 ms
50,236 KB |
testcase_35 | AC | 247 ms
47,732 KB |
testcase_36 | AC | 181 ms
43,540 KB |
testcase_37 | AC | 286 ms
50,360 KB |
ソースコード
import java.util.*; import java.io.*; 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(); Price[] prices = new Price[n]; TreeSet<Price> target = new TreeSet<>(); prices[0] = new Price(0, sc.nextInt()); target.add(prices[0]); int max = 0; int start = 0; int end = 0; for (int i = 1; i < n; i++) { prices[i] = new Price(i, sc.nextInt()); if (i - d - 1 >= 0) { target.remove(prices[i - d - 1]); } if (prices[i].price - target.first().price > max) { max = prices[i].price - target.first().price; start = target.first().day; end = i; } target.add(prices[i]); } if (max == 0) { System.out.println(0); } else { System.out.println(max * k); System.out.println(start + " " + end); } } static class Price implements Comparable<Price> { int day; int price; public Price(int day, int price) { this.day = day; this.price = price; } public int hashCode() { return day; } public boolean equals(Object o) { Price p = (Price)o; return day == p.day && price == p.price; } public int compareTo(Price another) { if (price == another.price) { return day - another.day; } else { return price - another.price; } } public String toString() { return day + ":" + price; } } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); 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 String nextLine() throws Exception { return br.readLine(); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }