結果
問題 |
No.1093 区間の和 / Sum of Range
|
ユーザー |
![]() |
提出日時 | 2020-08-18 13:34:29 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,261 bytes |
コンパイル時間 | 2,232 ms |
コンパイル使用メモリ | 79,508 KB |
実行使用メモリ | 75,956 KB |
最終ジャッジ日時 | 2024-10-12 02:39:20 |
合計ジャッジ時間 | 30,839 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 6 WA * 30 |
ソースコード
import java.util.*; public class Main { static final int MOD = 1000000007; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = sc.nextInt(); } long sum = 0; for (int i = 0; i < k; i++) { sum += arr[i]; } TreeMap<Long, Integer> map = new TreeMap<>(); map.put(sum, 1); for (int i = k; i < n; i++) { sum += arr[i] - arr[i - k]; if (map.containsKey(sum)) { map.put(sum, map.get(sum)); } else { map.put(sum, 1); } } Long start = Long.MIN_VALUE; int total = 0; while ((start = map.higherKey(start)) != null) { total += map.get(start); map.put(start, total); } map.put(Long.MIN_VALUE, 0); int q = sc.nextInt(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < q; i++) { long x = sc.nextInt(); sb.append(map.floorEntry(x).getValue()).append("\n"); } System.out.print(sb); } }