結果
| 問題 |
No.1890 Many Sequences Sum Queries
|
| ユーザー |
👑 |
| 提出日時 | 2023-03-28 17:24:58 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 621 bytes |
| コンパイル時間 | 833 ms |
| コンパイル使用メモリ | 76,052 KB |
| 最終ジャッジ日時 | 2025-02-11 18:52:13 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 1 WA * 24 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
long long n,q;cin>>n>>q;
vector<long long> A(n),B(n+1),C(n+1);
for(int i = 0; n > i; i++){
cin>>A[i];
B[i+1] = B[i]+A[i];
C[i+1] = C[i]+B[i+1];
}
for(int i = 0; q > i; i++){
long long x;cin>>x;
if(C[n] < x){
cout << -1 << endl;
continue;
}
long long ans = 0;
long long z = lower_bound(C.begin(),C.end(), x)-C.begin()-1;
ans += z*(z+1)/2;
if(z >= 0)x -= C[z];
long long y = lower_bound(B.begin(),B.end(), x)-B.begin();
ans += y;
cout << ans << endl;
}
}