-
Notifications
You must be signed in to change notification settings - Fork 26
/
game1.py
67 lines (59 loc) · 1.61 KB
/
game1.py
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from collections import deque
def minim(a, b):
if a == None:
return b
if b == None:
return a
if a < b:
return a
else:
return b
g = int(raw_input().strip())
for a0 in xrange(g):
n,m,x = raw_input().strip().split(' ')
n,m,x = [int(n),int(m),int(x)]
a = map(int, raw_input().strip().split(' '))
qa = deque(a)
b = map(int, raw_input().strip().split(' '))
qb = deque(b)
sum = 0
count = 0
#lena = len(qa)
#lenb = len(qb)
while sum <= x:
if not qa:
if not qb:
break
else:
if sum + qb[0] <= x:
sum = sum + qb.popleft()
count += 1
else:
break
else:
if not qb:
if sum + qa[0] <= x:
sum = sum + qa.popleft()
count += 1
else:
break
else:
if (sum + min(qa[0], qb[0])) <= x:
if qa[0] == min(qa[0], qb[0]):
sum = sum + qa.popleft()
count += 1
else:
sum = sum + qb.popleft()
count += 1
else:
break
#if (sum + minim(qa[0], qb[0])) <= x:
# if qa[0] == minim(qa[0], qb[0]):
# sum = sum + qa.popleft()
# count += 1
# else:
# sum = sum + qb.popleft()
# count += 1
#else:
# break
print count