結果

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

ソースコード

diff #

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

int main(void){
    std::cin.tie(nullptr); std::cin.sync_with_stdio(false); std::cout.sync_with_stdio(false);
    int n, k; std::cin >> n >> k;
    std::vector<int> A(n); for(int i = 0; i < n; ++i) std::cin >> A[i];
    std::vector<int> S(n - k + 1);{
        int val = 0; for(int i = 0; i < k; ++i) val += A[i];
        for(int i = k; i < n; ++i){
            S[i - k] = val; 
            val += A[i] - A[i - k];
        }
        S[n - k] = val;
    }
    std::sort(S.begin(), S.end());
    int q; std::cin >> q;
    while(q--){
        int x; std::cin >> x;
        const int len = std::upper_bound(S.cbegin(), S.cend(), x) - S.cbegin();
        std::cout << len << '\n';
    }

    return 0;
}
0