結果

問題 No.1093 区間の和 / Sum of Range
ユーザー tentententen
提出日時 2023-08-01 17:40:48
言語 Java21
(openjdk 21)
結果
AC  
実行時間 458 ms / 2,000 ms
コード長 2,302 bytes
コンパイル時間 3,006 ms
コンパイル使用メモリ 85,320 KB
実行使用メモリ 52,444 KB
最終ジャッジ日時 2024-04-19 16:53:43
合計ジャッジ時間 17,624 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
37,388 KB
testcase_01 AC 379 ms
48,816 KB
testcase_02 AC 232 ms
47,152 KB
testcase_03 AC 302 ms
51,560 KB
testcase_04 AC 292 ms
46,996 KB
testcase_05 AC 382 ms
48,752 KB
testcase_06 AC 248 ms
46,072 KB
testcase_07 AC 319 ms
46,748 KB
testcase_08 AC 381 ms
50,248 KB
testcase_09 AC 331 ms
47,444 KB
testcase_10 AC 388 ms
49,392 KB
testcase_11 AC 372 ms
49,884 KB
testcase_12 AC 347 ms
50,716 KB
testcase_13 AC 99 ms
39,292 KB
testcase_14 AC 393 ms
50,124 KB
testcase_15 AC 266 ms
45,864 KB
testcase_16 AC 453 ms
51,784 KB
testcase_17 AC 298 ms
47,352 KB
testcase_18 AC 321 ms
48,364 KB
testcase_19 AC 161 ms
42,456 KB
testcase_20 AC 256 ms
48,136 KB
testcase_21 AC 355 ms
48,244 KB
testcase_22 AC 437 ms
51,724 KB
testcase_23 AC 298 ms
45,884 KB
testcase_24 AC 284 ms
47,048 KB
testcase_25 AC 303 ms
46,532 KB
testcase_26 AC 366 ms
51,620 KB
testcase_27 AC 357 ms
48,720 KB
testcase_28 AC 355 ms
50,640 KB
testcase_29 AC 458 ms
50,236 KB
testcase_30 AC 224 ms
45,332 KB
testcase_31 AC 293 ms
48,216 KB
testcase_32 AC 288 ms
48,044 KB
testcase_33 AC 436 ms
52,444 KB
testcase_34 AC 159 ms
41,832 KB
testcase_35 AC 318 ms
48,656 KB
testcase_36 AC 436 ms
52,216 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] values = new int[n];
        for (int i = 0; i < n; i++) {
            values[i] = sc.nextInt();
        }
        int[] results = new int[n - k + 1];
        for (int i = 0; i < k; i++) {
            results[0] += values[i];
        }
        for (int i = k; i < n; i++) {
            results[i - k + 1] = results[i - k] - values[i - k] + values[i];
        }
        Arrays.sort(results);
        TreeMap<Integer, Integer> counts = new TreeMap<>();
        for (int i = 0; i <= n - k; i++) {
            counts.put(results[i], i + 1);
        }
        counts.put(Integer.MIN_VALUE, 0);
        int q = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        while (q-- > 0) {
            sb.append(counts.floorEntry(sc.nextInt()).getValue()).append("\n");
        }
        System.out.print(sb);
    }
} 
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0