-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path15.py
More file actions
45 lines (39 loc) · 1015 Bytes
/
15.py
File metadata and controls
45 lines (39 loc) · 1015 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from itertools import product
from bisect import bisect_right
n, s = map(int, input().split())
p = [int(input()) for _ in range(n)]
cnt = min(20, n)
item1 = []
bisect_item1 = []
for i in product([0, 1], repeat=cnt):
money, item = 0, []
for j in range(cnt):
if i[j] == 1:
money += p[j]
item.append(j + 1)
item1.append([money, item])
bisect_item1.append(money)
cnt = max(0, n - 20)
item2 = []
bisect_item2 = []
for i in product([0, 1], repeat=cnt):
money, item = 0, []
for j in range(cnt):
if i[j] == 1:
money += p[j + 20]
item.append(j + 21)
item2.append([money, item])
bisect_item2.append(money)
item2.sort(key=lambda x: x[0])
bisect_item2.sort()
ans = []
for money, item in item1:
if money > s: continue
p = bisect_right(bisect_item2, s - money)
if money + bisect_item2[p - 1] == s:
a = item
b = item2[p - 1][1]
ans.append(sorted(a + b))
ans.sort()
for i in ans:
print(*i)