結果
問題 |
No.1890 Many Sequences Sum Queries
|
ユーザー |
|
提出日時 | 2022-06-09 13:13:16 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 289 ms / 2,000 ms |
コード長 | 783 bytes |
コンパイル時間 | 169 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 77,056 KB |
最終ジャッジ日時 | 2024-09-21 05:33:22 |
合計ジャッジ時間 | 3,929 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 25 |
ソースコード
import bisect from itertools import accumulate n,q=map(int,input().split()) a=list(map(int,input().split())) a_ind=list(accumulate(a)) b=[] for i in a: b.append(i*(i+1)//2) b=list(accumulate(b)) for _ in range(q): s=int(input()) if s>b[-1]: print(-1) continue ind=bisect.bisect_right(b,s) if ind==0: ok=a[0];ng=0 while ok-ng>1: mid=(ok+ng)//2 if mid*(mid+1)//2>=s: ok=mid else: ng=mid print(ok) continue s-=b[ind-1] if s==0: print(a_ind[ind-1]) continue ok=a[ind];ng=0 while ok-ng>1: mid=(ok+ng)//2 if mid*(mid+1)//2>=s: ok=mid else: ng=mid print(a_ind[ind-1]+ok)