結果
| 問題 |
No.1110 好きな歌
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2020-10-15 16:22:37 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 1,344 ms / 5,000 ms |
| コード長 | 913 bytes |
| コンパイル時間 | 2,551 ms |
| コンパイル使用メモリ | 77,856 KB |
| 実行使用メモリ | 64,988 KB |
| 最終ジャッジ日時 | 2024-07-20 19:47:25 |
| 合計ジャッジ時間 | 42,235 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 51 |
ソースコード
import java.util.*;
public class Main {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int d = sc.nextInt();
Tune[] arr = new Tune[n];
for (int i = 0; i < n; i++) {
arr[i] = new Tune(i, sc.nextInt());
}
Arrays.sort(arr);
int[] ans = new int[n];
int left = 0;
for (int i = 0; i < n; i++) {
while (arr[i].value - arr[left].value >= d) {
left++;
}
ans[arr[i].idx] = left;
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < n; i++) {
sb.append(ans[i]).append("\n");
}
System.out.print(sb);
}
static class Tune implements Comparable<Tune> {
int idx;
int value;
public Tune(int idx, int value) {
this.idx = idx;
this.value = value;
}
public int compareTo(Tune another) {
return value - another.value;
}
}
}
tenten