Google Code Jam 2012 Qualification Round Problem B. Speaking in Tongues

Dancing With the Googlers

最高点数をpとすると、合計点数の最小は、最高と最低の差が1以下の場合は3p-2、2以下の場合は3p-4である。ただし、p未満にはならない。合計点数がこの最小以上のGooglerを数える。

for i in range(input()):t=map(int,raw_input().split());f=lambda a:sum(int(x>=max(t[2]*3-a,t[2]))for x in t[3:]);print("Case #%s: %s"%(i+1,f(2)+min(f(4)-f(2),t[1])))