https://leetcode.com/problems/put-marbles-in-bags/description/
https://leetcode.com/contest/weekly-contest-330/problems/put-marbles-in-bags/
from nyu_ldf
class Solution(object):
def putMarbles(self, weights, k):
"""
:type weights: List[int]
:type k: int
:rtype: int
"""
v, d = [0] * (len(weights) - 1), 0
for i in range(len(weights) - 1):
v[i] = weights[i] + weights[i + 1]
v.sort()
for i in range(k - 1):
d += v[len(weights) - 2 - i] - v[i]
return d