Skip to content

Instantly share code, notes, and snippets.

@nagataka
Last active August 29, 2015 14:19
Show Gist options
  • Select an option

  • Save nagataka/8de39a3bde43dded2144 to your computer and use it in GitHub Desktop.

Select an option

Save nagataka/8de39a3bde43dded2144 to your computer and use it in GitHub Desktop.
Google Code Jam 2015 Problem A. Standing Ovation - https://code.google.com/codejam/contest/6224486/dashboard#s=p0
def calc(max_shyness, data_list):
if max_shyness == 0:
return 0
else:
total_count, required_count = 0, 0
for i in range(0, max_shyness+1):
if data_list[i] != 0:
if total_count >= i:
total_count += data_list[i]
else:
diff = i - total_count
required_count += diff
total_count = total_count + diff + data_list[i]
return required_count
def calc_required_number(data):
if len(data) == 1:
return -1
if len(data) == 2:
max_shyness, data_list = data[0], data[1]
return calc(int(max_shyness), list(map(int, data_list)))
try:
with open('a-large-practice.txt') as datasets:
count = 0
for line in datasets:
res = calc_required_number((line.rstrip()).split(' '))
if res != -1:
print("Case #"+str(count)+": " + str(res))
count += 1
except IOError as err:
print('File error: ' + str(err))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment