def solve(self, cipher):
        N, K, C = cipher

        C.sort(reverse=True)

        group_cnt = N / K + 1  # 1 is the last remaining group
        total_cost = 0
        for i in xrange(group_cnt):
            unit_cost = i + 1
            total_cost += unit_cost * sum(C[i * K:(i + 1) * K])
        return total_cost
Array math
dataset/ETHPy150Open algorhythms/HackerRankAlgorithms/Flowers.py/Solution.solve