結果

問題 No.1093 区間の和 / Sum of Range
ユーザー CELICACELICA
提出日時 2020-08-11 15:36:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 1,071 bytes
コンパイル時間 1,975 ms
コンパイル使用メモリ 172,276 KB
実行使用メモリ 6,932 KB
最終ジャッジ日時 2024-04-17 17:18:22
合計ジャッジ時間 5,866 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 22 ms
5,376 KB
testcase_02 AC 10 ms
5,376 KB
testcase_03 AC 16 ms
5,376 KB
testcase_04 AC 15 ms
5,376 KB
testcase_05 AC 30 ms
5,540 KB
testcase_06 AC 10 ms
5,376 KB
testcase_07 AC 19 ms
5,376 KB
testcase_08 AC 23 ms
5,376 KB
testcase_09 AC 25 ms
5,376 KB
testcase_10 AC 21 ms
5,376 KB
testcase_11 AC 25 ms
5,720 KB
testcase_12 AC 22 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 25 ms
5,520 KB
testcase_15 AC 11 ms
5,376 KB
testcase_16 AC 31 ms
5,856 KB
testcase_17 AC 22 ms
5,376 KB
testcase_18 AC 18 ms
5,376 KB
testcase_19 AC 4 ms
5,376 KB
testcase_20 AC 16 ms
5,376 KB
testcase_21 AC 32 ms
5,456 KB
testcase_22 AC 35 ms
6,100 KB
testcase_23 AC 22 ms
5,376 KB
testcase_24 AC 14 ms
5,376 KB
testcase_25 AC 25 ms
5,568 KB
testcase_26 AC 27 ms
5,376 KB
testcase_27 AC 26 ms
5,524 KB
testcase_28 AC 26 ms
5,376 KB
testcase_29 AC 43 ms
6,932 KB
testcase_30 AC 7 ms
5,376 KB
testcase_31 AC 12 ms
5,376 KB
testcase_32 AC 15 ms
5,376 KB
testcase_33 AC 35 ms
5,992 KB
testcase_34 AC 4 ms
5,376 KB
testcase_35 AC 25 ms
5,376 KB
testcase_36 AC 34 ms
6,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    vector<ll> va(n);

    for (int i = 0; i < n; ++i)
        cin >> va[i];

    int q;
    cin >> q;

    vector<ll> vx(q);
    for (int i = 0; i < q; ++i)
        cin >> vx[i];

    vector<ll> vs(n - k + 1);
    for (int i = 0; i < k; ++i)
        vs[0] += va[i];

    for (int i = 1; i < n - k + 1; ++i)
        vs[i] = vs[i - 1] - va[i - 1] + va[i + k - 1];

    sort(vs.begin(), vs.end());

    vector<ll> res;
    for (int i = 0; i < q; ++i)
    {
        vector<ll>::iterator it = upper_bound(vs.begin(), vs.end(), vx[i]);
        if (it == vs.begin())
        {
            res.push_back(0);
            continue;
        }
        if (it == vs.end())
        {
            res.push_back(n - k + 1);
            continue;
        }
        ll d = distance(vs.begin(), --it) + 1;
        res.push_back(d);
    }

    for (const auto& iv : res)
        printf("%lld\n", iv);

    return 0;
}
0