結果
| 問題 |
No.1890 Many Sequences Sum Queries
|
| ユーザー |
|
| 提出日時 | 2022-06-09 12:40:07 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 542 bytes |
| コンパイル時間 | 159 ms |
| コンパイル使用メモリ | 12,544 KB |
| 実行使用メモリ | 10,880 KB |
| 最終ジャッジ日時 | 2024-09-21 05:32:47 |
| 合計ジャッジ時間 | 9,584 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 6 WA * 17 RE * 2 |
ソースコード
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())
ind=bisect.bisect_right(b,s)
if ind==n and b[ind-1]<s:
print(-1)
continue
s-=b[ind-1]
ans=a_ind[ind-1]
ng=-1;ok=a[ind]
while ok-ng>1:
mid=(ok+ng)//2
if mid*(mid+1)//2>=s:
ok=mid
else:
ng=mid
ans+=ok
print(ans)