結果

問題 No.1890 Many Sequences Sum Queries
ユーザー DrDrpilotDrDrpilot
提出日時 2022-06-09 13:06:53
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 564 bytes
コンパイル時間 102 ms
コンパイル使用メモリ 11,836 KB
実行使用メモリ 10,200 KB
最終ジャッジ日時 2023-10-21 04:28:35
合計ジャッジ時間 8,480 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 764 ms
10,200 KB
testcase_02 AC 31 ms
10,164 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 30 ms
10,164 KB
testcase_16 AC 31 ms
10,164 KB
testcase_17 AC 31 ms
10,164 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 30 ms
10,164 KB
testcase_22 AC 30 ms
10,164 KB
testcase_23 AC 30 ms
10,164 KB
testcase_24 WA -
testcase_25 AC 30 ms
10,164 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
    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)
0