結果

問題 No.2025 Select $k$-th Submultiset
ユーザー mkawa2mkawa2
提出日時 2022-07-30 18:52:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 340 ms / 2,000 ms
コード長 1,519 bytes
コンパイル時間 304 ms
コンパイル使用メモリ 87,012 KB
実行使用メモリ 83,724 KB
最終ジャッジ日時 2023-09-27 20:35:13
合計ジャッジ時間 14,848 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
71,540 KB
testcase_01 AC 66 ms
71,416 KB
testcase_02 AC 78 ms
76,128 KB
testcase_03 AC 266 ms
83,040 KB
testcase_04 AC 234 ms
83,420 KB
testcase_05 AC 322 ms
82,640 KB
testcase_06 AC 304 ms
82,432 KB
testcase_07 AC 316 ms
83,724 KB
testcase_08 AC 335 ms
83,336 KB
testcase_09 AC 327 ms
82,940 KB
testcase_10 AC 322 ms
83,284 KB
testcase_11 AC 319 ms
82,780 KB
testcase_12 AC 313 ms
82,916 KB
testcase_13 AC 297 ms
83,160 KB
testcase_14 AC 306 ms
83,312 KB
testcase_15 AC 319 ms
83,460 KB
testcase_16 AC 302 ms
82,840 KB
testcase_17 AC 309 ms
82,984 KB
testcase_18 AC 305 ms
82,384 KB
testcase_19 AC 315 ms
83,028 KB
testcase_20 AC 315 ms
82,548 KB
testcase_21 AC 295 ms
82,524 KB
testcase_22 AC 294 ms
82,272 KB
testcase_23 AC 340 ms
83,568 KB
testcase_24 AC 292 ms
82,496 KB
testcase_25 AC 70 ms
71,280 KB
testcase_26 AC 68 ms
71,364 KB
testcase_27 AC 66 ms
71,364 KB
testcase_28 AC 68 ms
71,276 KB
testcase_29 AC 67 ms
71,400 KB
testcase_30 AC 69 ms
71,492 KB
testcase_31 AC 70 ms
71,292 KB
testcase_32 AC 67 ms
71,440 KB
testcase_33 AC 68 ms
71,244 KB
testcase_34 AC 65 ms
71,292 KB
testcase_35 AC 67 ms
71,292 KB
testcase_36 AC 76 ms
75,636 KB
testcase_37 AC 68 ms
71,196 KB
testcase_38 AC 65 ms
71,420 KB
testcase_39 AC 67 ms
71,296 KB
testcase_40 AC 66 ms
71,120 KB
testcase_41 AC 65 ms
71,420 KB
testcase_42 AC 65 ms
71,344 KB
testcase_43 AC 67 ms
71,504 KB
testcase_44 AC 70 ms
71,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
dij = [(-1, 1), (-1, 0), (-1, -1), (1, -1), (1, 1)]
inf = (1 << 63)-1
# inf = (1 << 31)-1
# md = 10**9+7
md = 998244353

from bisect import bisect_right

lim = 10**18
n, L = LI()
cc = LI()

dp = [[0]*(L+2) for _ in range(n)]
c = cc[-1]
dp[-1][:c+2] = list(range(c+2))
dp[-1][c+2:] = [c+1]*(L-c)
# p2D(dp)

for i in range(n-1)[::-1]:
    c = cc[i]
    for j in range(L+1):
        l, r = max(0, j-c), j+1
        dp[i][j+1] = dp[i][j]+dp[i+1][r]-dp[i+1][l]
# p2D(dp)

mx = dp[0][L+1]-dp[0][L]

for _ in range(II()):
    k = II()
    if k > mx:
        print(-1)
        continue
    k -= 1
    ans = [0]*n
    s = 0
    for i in range(n-1):
        l = max(0, L-(s+cc[i]))
        r = bisect_right(dp[i+1], k+dp[i+1][l])-1
        ans[i] = L-s-r
        s += ans[i]
        k -= dp[i+1][r]-dp[i+1][l]
        # print(l, r, s, k)
    ans[-1] = L-s
    print(*ans)
0