結果

問題 No.1890 Many Sequences Sum Queries
ユーザー lloyzlloyz
提出日時 2022-04-06 22:36:57
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 589 bytes
コンパイル時間 986 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 77,440 KB
最終ジャッジ日時 2024-05-05 19:59:30
合計ジャッジ時間 4,465 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 262 ms
76,288 KB
testcase_01 AC 304 ms
76,416 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 40 ms
51,840 KB
testcase_06 AC 37 ms
51,840 KB
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 37 ms
52,224 KB
testcase_16 AC 37 ms
51,968 KB
testcase_17 AC 39 ms
51,968 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 39 ms
51,968 KB
testcase_21 AC 39 ms
52,096 KB
testcase_22 AC 39 ms
51,712 KB
testcase_23 WA -
testcase_24 AC 38 ms
51,712 KB
testcase_25 AC 37 ms
51,712 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect_left

n, q = map(int, input().split())
A = list(map(int, input().split()))
AA = [0]
I = [0]
for i in range(n):
    s = A[i] * (A[i] + 1) // 2
    AA.append(AA[-1] + s)
    I.append(I[-1] + A[i])
for _ in range(q):
    s = int(input())
    idx = bisect_left(AA, s)
    idx -= 1
    if idx == n:
        print(-1)
        continue
    s -= AA[idx]
    left = 0
    right = A[i]
    while right - left > 1:
        mid = (left + right) // 2
        if mid * (mid + 1) // 2 >= s:
            right = mid
        else:
            left = mid
    print(I[idx] + right)
0