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
| import sys
def check_t(down):
t_all=0
for i in range(len(down)):
if down[i]=='1':
t_all+=appt[i]
#print t_all,t,down
return t_all<=t
def get_m(down):
m_all=0
for i in range(len(down)):
if down[i]=='1':
m_all+=appm[i]
return m_all
def get_prior(a,b):
#print a
#print b
return a if int(a,2)>int(b,2) else b
def parse(down):
res=[]
res.extend([str(i+1) for i in range(len(down)) if down[i]=='1'])
print (" ".join(res)).strip() #,down
t=int(sys.stdin.readline().strip())
appt=map(int,sys.stdin.readline().strip().split())
appm=map(int,sys.stdin.readline().strip().split())
length=len(appt)
res,money="0"*length,0
for i in xrange(2**length):
down=bin(i)[2:].zfill(length)
if check_t(down):
tmpm=get_m(down)
if tmpm >money:
res,money=down,tmpm
elif tmpm == money:
res=get_prior(down,res)
parse(res)
|