結果

問題 No.1890 Many Sequences Sum Queries
ユーザー kokatsukokatsu
提出日時 2022-11-02 22:24:07
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 522 bytes
コンパイル時間 2,812 ms
コンパイル使用メモリ 207,412 KB
実行使用メモリ 6,648 KB
最終ジャッジ日時 2023-09-04 18:51:10
合計ジャッジ時間 6,640 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
6,648 KB
testcase_01 AC 78 ms
5,876 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 3 ms
5,856 KB
testcase_07 AC 33 ms
6,244 KB
testcase_08 AC 9 ms
6,140 KB
testcase_09 AC 11 ms
6,112 KB
testcase_10 AC 74 ms
4,384 KB
testcase_11 AC 37 ms
5,716 KB
testcase_12 AC 56 ms
4,940 KB
testcase_13 AC 59 ms
4,924 KB
testcase_14 AC 33 ms
4,860 KB
testcase_15 AC 1 ms
4,384 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,384 KB
testcase_19 AC 1 ms
4,384 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,384 KB
testcase_22 AC 2 ms
4,384 KB
testcase_23 AC 1 ms
4,384 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

void main() {
    long N, Q;
    readf("%d %d\n", N, Q);

    auto A = readln.chomp.split.to!(long[]);

    long len = A.sum, pos;
    auto B = new long[](len);
    foreach (a; A) {
        foreach (i; 1 .. a+1) B[pos++] = i;
    }

    auto C = B.cumulativeFold!"a + b".array.assumeSorted;

    foreach (_; 0 .. Q) {
        long S;
        readf("%d\n", S);

        auto ub = C.upperBound(S-1);

        long res = -1;
        if (!ub.empty) res = len - ub.length.to!long + 1;

        res.writeln;
    }
}
0