結果

問題 No.1890 Many Sequences Sum Queries
ユーザー HIcoder
提出日時 2023-07-14 17:01:03
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 174 ms / 2,000 ms
コード長 923 bytes
コンパイル時間 1,029 ms
コンパイル使用メモリ 109,412 KB
最終ジャッジ日時 2025-02-15 10:21:25
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<set> 
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<numeric>
#include<queue>
#include<cmath>
#include <unordered_set>
using namespace std;
typedef long long ll;
const ll INF=1LL<<60;
typedef pair<ll,ll> P;
typedef pair<int,P> PP;
const ll MOD=1e9+7;

int main(){
    int N,Q;
    cin>>N>>Q;
    vector<int> A(N);
    vector<int> B;
    for(int i=0;i<N;i++){
        cin>>A[i];
        for(int j=1;j<=A[i];j++){
            B.push_back(j);
        }
    }
    int n=B.size();
    vector<ll> sumB(n);
    sumB[0]=B[0];
    for(int i=1;i<n;i++){
        sumB[i]=sumB[i-1]+B[i];
    }

    for(int q=0;q<Q;q++){
        ll S;
        cin>>S;
        auto it=lower_bound(sumB.begin(),sumB.end(),S);

        if(it==sumB.end()){
            cout<<-1<<endl;
        }else{
            int c=it-sumB.begin();
            cout<<c+1<<endl;

        }

    }

}
0