My solution passed both visible test sets, but I got a "TIME_LIMIT_EXCEEDED"
error on the hidden one. As far as I can tell, I did exactly what was described
to solve test set 3 in the analysis. What did I do wrong?
(Python 3)
for T in range(int(input())):
N, L = list(map(int, input().split()))
C = list(map(int, input().split()))
if 100 % N != 0:
remaining = N - sum(C)
counts = C + [0 for i in range(remaining)]
needed = []
for cnt in counts:
num = cnt
while num * 100 / N - int(num * 100 / N) < 0.5:
num += 1
needed.append(num - cnt)
needed, counts = list(map(list, zip(*sorted(zip(needed, counts)))))
for i in range(len(counts)):
if needed[i] <= remaining:
counts[i] += needed[i]
remaining -= needed[i]
counts[-1] += remaining
result = []
for cnt in counts:
percentage = cnt * 100 / N
if percentage - int(percentage) < 0.5:
result.append(int(percentage))
else:
result.append(int(percentage) + 1)
print('Case #' + str(T + 1) + ': ' + str(sum(result)))
else:
print('Case #' + str(T + 1) + ': 100')
--
You received this message because you are subscribed to the Google Groups
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-code/c7efd9ae-a678-476d-b579-e64bf35c6514%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.