結果
| 問題 | No.1093 区間の和 / Sum of Range |
| ユーザー |
tenten
|
| 提出日時 | 2020-12-28 19:06:46 |
| 言語 | Java (openjdk 25.0.1) |
| 結果 |
AC
|
| 実行時間 | 824 ms / 2,000 ms |
| コード長 | 1,488 bytes |
| 記録 | |
| コンパイル時間 | 2,986 ms |
| コンパイル使用メモリ | 78,320 KB |
| 実行使用メモリ | 58,636 KB |
| 最終ジャッジ日時 | 2024-10-03 11:40:35 |
| 合計ジャッジ時間 | 26,186 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 36 |
ソースコード
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
int[] sums = new int[n + 1];
int[] values = new int[n - k + 2];
for (int i = 1; i <= n; i++) {
sums[i] = sums[i - 1] + sc.nextInt();
if (i - k >= 0) {
values[i - k] = sums[i] - sums[i - k];
}
}
values[n - k + 1] = Integer.MAX_VALUE;
Arrays.sort(values);
int q = sc.nextInt();
Question[] questions = new Question[q];
for (int i = 0; i < q; i++) {
questions[i] = new Question(i, sc.nextInt());
}
Arrays.sort(questions);
int[] ans = new int[q];
int idx = 0;
for (Question x : questions) {
while (values[idx] <= x.value) {
idx++;
}
ans[x.idx] = idx;
}
StringBuilder sb = new StringBuilder();
for (int x : ans) {
sb.append(x).append("\n");
}
System.out.print(sb);
}
static class Question implements Comparable<Question> {
int idx;
int value;
public Question(int idx, int value) {
this.idx = idx;
this.value = value;
}
public int compareTo(Question another) {
return value - another.value;
}
}
}
tenten