Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagepy
titleLuck Balance
linenumberstrue
def luckBalance(k, contests):
    sorted_contests = sorted(contests, key=lambda x: (x[1], -x[0]))
    total_sum = 0
    for i in sorted_contests:
        if i[1] == 0:
            total_sum += i[0]
        elif k > 0:
            total_sum += i[0]
            k -= 1
        else:
            total_sum -= i[0]

    return total_sum
Code Block
languagepy
titleGreedy Florist
linenumberstrue
def getMinimumCost(k, c):
    sorted_c = sorted(c, reverse=True)

    sum = 0
    for i, val in enumerate(sorted_c):
        mul = i // k
        sum += (mul + 1) * sorted_c[i]

    return sum