結果
問題 |
No.1890 Many Sequences Sum Queries
|
ユーザー |
👑 |
提出日時 | 2023-03-28 17:10:32 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 595 bytes |
コンパイル時間 | 1,009 ms |
コンパイル使用メモリ | 75,920 KB |
最終ジャッジ日時 | 2025-02-11 18:52:04 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 1 WA * 24 |
ソースコード
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main(){ int 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; auto z = upper_bound(C.begin(),C.end(), x)-C.begin()-1; ans += z*(z+1)/2; x -= C[z]; auto y = lower_bound(B.begin(),B.end(), x)-B.begin(); ans += y; cout << ans << endl; } }