結果

問題 No.1093 区間の和 / Sum of Range
ユーザー tentententen
提出日時 2020-12-28 19:06:46
言語 Java21
(openjdk 21)
結果
AC  
実行時間 973 ms / 2,000 ms
コード長 1,488 bytes
コンパイル時間 2,317 ms
コンパイル使用メモリ 78,428 KB
実行使用メモリ 70,168 KB
最終ジャッジ日時 2024-04-14 13:18:01
合計ジャッジ時間 31,324 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 137 ms
53,900 KB
testcase_01 AC 706 ms
62,656 KB
testcase_02 AC 558 ms
59,540 KB
testcase_03 AC 704 ms
59,680 KB
testcase_04 AC 644 ms
59,392 KB
testcase_05 AC 871 ms
67,840 KB
testcase_06 AC 514 ms
59,832 KB
testcase_07 AC 701 ms
59,840 KB
testcase_08 AC 773 ms
59,952 KB
testcase_09 AC 782 ms
62,156 KB
testcase_10 AC 733 ms
59,760 KB
testcase_11 AC 785 ms
65,788 KB
testcase_12 AC 696 ms
59,652 KB
testcase_13 AC 219 ms
57,008 KB
testcase_14 AC 817 ms
62,144 KB
testcase_15 AC 561 ms
59,952 KB
testcase_16 AC 879 ms
68,240 KB
testcase_17 AC 757 ms
62,216 KB
testcase_18 AC 648 ms
60,360 KB
testcase_19 AC 328 ms
58,916 KB
testcase_20 AC 577 ms
60,368 KB
testcase_21 AC 870 ms
67,988 KB
testcase_22 AC 927 ms
68,312 KB
testcase_23 AC 742 ms
62,088 KB
testcase_24 AC 641 ms
59,564 KB
testcase_25 AC 832 ms
66,200 KB
testcase_26 AC 816 ms
62,088 KB
testcase_27 AC 854 ms
66,552 KB
testcase_28 AC 797 ms
62,004 KB
testcase_29 AC 973 ms
70,168 KB
testcase_30 AC 454 ms
59,704 KB
testcase_31 AC 558 ms
59,616 KB
testcase_32 AC 652 ms
59,764 KB
testcase_33 AC 879 ms
67,824 KB
testcase_34 AC 312 ms
59,000 KB
testcase_35 AC 818 ms
67,160 KB
testcase_36 AC 884 ms
66,068 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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