結果

問題 No.1093 区間の和 / Sum of Range
ユーザー tentententen
提出日時 2020-08-18 13:34:29
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,261 bytes
コンパイル時間 2,392 ms
コンパイル使用メモリ 79,556 KB
実行使用メモリ 71,092 KB
最終ジャッジ日時 2024-04-20 07:31:20
合計ジャッジ時間 30,930 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 132 ms
41,424 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 733 ms
54,160 KB
testcase_12 WA -
testcase_13 AC 231 ms
45,740 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 683 ms
50,232 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 666 ms
49,312 KB
testcase_24 WA -
testcase_25 AC 720 ms
50,212 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 327 ms
48,684 KB
testcase_35 WA -
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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);
    }
} 
0