結果
| 問題 |
No.489 株に挑戦
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2021-11-12 08:35:33 |
| 言語 | Java (openjdk 23) |
| 結果 |
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 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 35 |
ソースコード
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();
}
}
tenten