結果

問題 No.1093 区間の和 / Sum of Range
ユーザー Mister
提出日時 2020-08-01 07:47:25
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 725 bytes
コンパイル時間 1,062 ms
コンパイル使用メモリ 78,956 KB
最終ジャッジ日時 2025-01-12 12:14:43
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>

void solve() {
    int n, k;
    std::cin >> n >> k;

    std::vector<int> acc(n + 1, 0);
    for (int i = 0; i < n; ++i) {
        int x;
        std::cin >> x;
        acc[i + 1] = acc[i] + x;
    }

    std::vector<int> ss(n - k + 1);
    for (int i = 0; i <= n - k; ++i) {
        ss[i] = acc[i + k] - acc[i];
    }
    std::sort(ss.begin(), ss.end());

    int q;
    std::cin >> q;
    while (q--) {
        int x;
        std::cin >> x;
        std::cout << std::upper_bound(ss.begin(), ss.end(), x) - ss.begin()
                  << "\n";
    }
}

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

    solve();

    return 0;
}
0