Skip to content

Instantly share code, notes, and snippets.

@johnkariuki
Created April 8, 2016 12:52
Show Gist options
  • Save johnkariuki/de336d8c62aaf7c51895f710539fbe77 to your computer and use it in GitHub Desktop.
Save johnkariuki/de336d8c62aaf7c51895f710539fbe77 to your computer and use it in GitHub Desktop.
Google code jam - Africa 2010, Qualification Round
with open('A-large-practice.in') as f:
lines = f.readlines()
testcases = int(lines[0])
data = [testcases]
last_pos = 1
with open('output.txt', 'wt') as output:
for i in range(1, testcases + 1):
C = int(lines[last_pos])
I = int(lines[last_pos + 1])
P = {int(index + 1) : int(value) for index, value in\
enumerate(lines[last_pos + 2].split()) if int(value) < C}
last_pos += 3
if len(P) == 2:
output.write("Case #{case}: {pos1} {pos2}\n".format(case = i,
pos1 = P.keys()[0],
pos2 = P.keys()[1]))
else:
items = []
p_inv = {v: k for k, v in P.iteritems()}
if i == 3:
print p_inv.items()
values = P.values()
for index, value in enumerate(values):
ans = list(filter(lambda x:x == C - value, values[index + 1:]))
if ans:
items.append(p_inv[value])
items.append(p_inv[ans[0]])
items.sort()
output.write("Case #{case}: {pos1} {pos2}\n".format(case = i,
pos1 = items[0],
pos2 = items[1]))
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment