leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
2551.cpp (414B)
0 class Solution {
1 public:
2 long long putMarbles(vector<int> &weights, int k) {
3 long long res = 0, n = weights.size();
5 for (int i = 0; i < n - 1; i++)
6 weights[i] += weights[i + 1];
8 weights.resize(n - 1);
9 sort(weights.begin(), weights.end());
11 for (int i = 0; i < k - 1; i++)
12 res += weights[n - 2 - i] - weights[i];
14 return res;
15 }
16 };