In [1]:
# Sample Input
#
#5
#7 1 400 2 2
In [2]:
fin = open ('lemonade.in', 'r')
fout = open ('lemonde.out', 'w')
N = int(fin.readline().strip())
W = [int(x) for x in fin.readline().split()]
W.sort(reverse=True)
print(N)
print(W)
In [3]:
# An edge case to worry about: if the smallest W is bigger than N-1, then
# the loop will finish with i=N-1, when the true answer is i=N
# so check for that case before looping
if W[-1]>=N-1:
i=N
else:
for i in range(1,N):
if i>W[i]:
break
print("answer",i)
fout.write(str(i)+"\n")
fout.close()