結果

問題 No.1093 区間の和 / Sum of Range
ユーザー KKT89
提出日時 2020-06-27 10:40:18
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 147 ms / 2,000 ms
コード長 708 bytes
コンパイル時間 775 ms
コンパイル使用メモリ 91,492 KB
最終ジャッジ日時 2025-01-11 12:39:33
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <set>
using namespace std;
typedef long long int ll;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,k; cin >> n >> k;
    vector<int> a(n);
    vector<int> v;
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    int sum=0;
    for(int i=0;i<n;i++){
        sum+=a[i];
        if(i>=k){
            sum-=a[i-k];
        }
        if(i>=k-1){
            v.push_back(sum);
        }
    }
    sort(v.begin(), v.end());
    int q; cin >> q;
    while(q--){
        int x; cin >> x;
        cout << upper_bound(v.begin(), v.end(),x)-v.begin() << endl;
    }
}
0