Skip to content

Instantly share code, notes, and snippets.

@whatalnk
Created October 11, 2015 04:02
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 whatalnk/81a24db510c370fe56fd to your computer and use it in GitHub Desktop.
Save whatalnk/81a24db510c370fe56fd to your computer and use it in GitHub Desktop.
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