Skip to content

Instantly share code, notes, and snippets.

@nishidy
Created June 29, 2015 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nishidy/7e1392fa3333607b2577 to your computer and use it in GitHub Desktop.
Save nishidy/7e1392fa3333607b2577 to your computer and use it in GitHub Desktop.
Round 1C 2015: Problem C. Less Money, More Problems
T=int(raw_input())
t=0
while t<T:
C,D,V=map(lambda x:int(x),raw_input().split())
d=sorted(map(lambda x:int(x),raw_input().split()))
a=0;n=1;s=0;pn=0
while n<=V:
if n in d:
n,s,pn=(n*C)+s+1,(n*C)+s,n
else:
for j in range(D):
if n>d[j] and d[j]>pn:
k=0
while j+k<D and n>d[j+k] and d[j+k]>pn:
s+=d[j+k]*C
k+=1
n,pn=s+1,n
break
if d[j]>n:
a+=1
n,s,pn=(n*C)+s+1,(n*C)+s,n
break
else:
a+=1
n,s,pn=(n*C)+s+1,(n*C)+s,n
t+=1
print "Case #%d: %d"%(t,a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment