Create a gist now

Instantly share code, notes, and snippets.

TopCoder SRM 670
class Cdgame():
def rescount(self, a, b):
sum_a = sum(a)
sum_b = sum(b)
res = []
for i in a:
for j in b:
res.append((sum_a-i+j)*(sum_b-j+i))
return(len(set(res)))
class Drbalance():
def lesscng(self, s, k):
l = list(s)
res = 0
while True:
costs = [l.count("+") - l.count("-")]
for i in range(len(l)):
ll = l[:-i]
costs.append(ll.count("+") - ll.count("-"))
costs_sum = len([i for i in costs if i < 0])
if costs_sum > k:
i = l.index("-")
l[i] = "+"
res += 1
else:
return res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment