結果
問題 | No.489 株に挑戦 |
ユーザー | tenten |
提出日時 | 2021-11-12 08:35:33 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 401 ms / 1,000 ms |
コード長 | 2,641 bytes |
コンパイル時間 | 2,478 ms |
コンパイル使用メモリ | 80,560 KB |
実行使用メモリ | 65,016 KB |
最終ジャッジ日時 | 2024-05-03 13:54:57 |
合計ジャッジ時間 | 11,600 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 312 ms
58,880 KB |
testcase_01 | AC | 276 ms
61,108 KB |
testcase_02 | AC | 72 ms
51,216 KB |
testcase_03 | AC | 70 ms
51,228 KB |
testcase_04 | AC | 48 ms
50,432 KB |
testcase_05 | AC | 71 ms
51,360 KB |
testcase_06 | AC | 83 ms
51,820 KB |
testcase_07 | AC | 83 ms
51,552 KB |
testcase_08 | AC | 82 ms
50,944 KB |
testcase_09 | AC | 87 ms
51,092 KB |
testcase_10 | AC | 76 ms
51,204 KB |
testcase_11 | AC | 74 ms
50,944 KB |
testcase_12 | AC | 82 ms
51,016 KB |
testcase_13 | AC | 82 ms
51,436 KB |
testcase_14 | AC | 76 ms
51,540 KB |
testcase_15 | AC | 170 ms
54,788 KB |
testcase_16 | AC | 373 ms
63,432 KB |
testcase_17 | AC | 165 ms
55,964 KB |
testcase_18 | AC | 268 ms
58,756 KB |
testcase_19 | AC | 252 ms
58,764 KB |
testcase_20 | AC | 358 ms
63,048 KB |
testcase_21 | AC | 220 ms
58,928 KB |
testcase_22 | AC | 190 ms
54,508 KB |
testcase_23 | AC | 254 ms
57,504 KB |
testcase_24 | AC | 401 ms
63,540 KB |
testcase_25 | AC | 49 ms
50,424 KB |
testcase_26 | AC | 277 ms
64,784 KB |
testcase_27 | AC | 319 ms
61,652 KB |
testcase_28 | AC | 74 ms
52,920 KB |
testcase_29 | AC | 48 ms
50,364 KB |
testcase_30 | AC | 333 ms
64,544 KB |
testcase_31 | AC | 306 ms
65,016 KB |
testcase_32 | AC | 273 ms
58,844 KB |
testcase_33 | AC | 391 ms
62,780 KB |
testcase_34 | AC | 359 ms
60,708 KB |
testcase_35 | AC | 243 ms
58,992 KB |
testcase_36 | AC | 180 ms
56,448 KB |
testcase_37 | AC | 287 ms
61,572 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(); } }