Created
April 17, 2012 00:42
-
-
Save ameerkat/2402598 to your computer and use it in GitHub Desktop.
2012 Code Jam Qualifier B
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def gen_trip(n, p): | |
flag = False | |
trips = [] | |
for i in range(0,11): | |
for j in range(0, 11): | |
for k in range(0, 11): | |
if i + j + k == n: | |
if(max([i,j,k]) - min([i,j,k]) <= 2 and max([i,j,k]) >= p): | |
trips.append([i, j, k]) | |
if(max([i,j,k]) - min([i,j,k]) <= 1): | |
flag = True | |
return trips, flag | |
f = open("B-large.in") | |
T = f.readline() | |
c = 1 | |
for line in f: | |
max_g = 0 | |
i = map(int, line.strip().split()) | |
N = i[0] | |
S = i[1] | |
p = i[2] | |
t_i = i[3:] | |
for t in t_i: | |
g = gen_trip(t,p) | |
#print g | |
if g[0]: | |
if g[1]: | |
max_g += 1 | |
elif S > 0: | |
max_g += 1 | |
S -= 1 | |
print "Case #" + str(c) + ": " + str(max_g) | |
c += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment