結果

問題 No.1093 区間の和 / Sum of Range
ユーザー 👑 CleyL
提出日時 2023-02-03 01:00:08
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 214 ms / 2,000 ms
コード長 599 bytes
コンパイル時間 820 ms
コンパイル使用メモリ 84,208 KB
最終ジャッジ日時 2025-02-10 08:21:36
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
int main(){
  int n,k;cin>>n>>k;
  long long sm = 0;
  queue<long long> A;
  for(int i = 0; k > i; i++){
    long long x;cin>>x;
    A.push(x);
    sm += x;
  }
  vector<long long> B;
  B.push_back(sm);
  for(int i = 0; n-k > i; i++){
    long long x;cin>>x;
    sm += x;A.push(x);
    sm -= A.front(); A.pop();
    B.push_back(sm);
  }
  sort(B.begin(),B.end());
  int q;cin>>q;
  for(int i = 0; q > i; i++){
    long long x;cin>>x;
    auto z = upper_bound(B.begin(),B.end(),x);
    cout << z-B.begin() << endl;
  }
}
0