提交时间:2024-08-19 21:30:16
运行 ID: 167964
#include <iostream> #include <vector> #include <algorithm> int calculateMinimumEffort(std::vector<int>& lazyValues) { int totalEffort = 0; while (lazyValues.size() > 1) { std::sort(lazyValues.begin(), lazyValues.end()); // 对懒散值进行排序 int min1 = lazyValues[0]; int min2 = lazyValues[1]; int combinedValue = min1 + min2; totalEffort += combinedValue; lazyValues.erase(lazyValues.begin(), lazyValues.begin() + 2); lazyValues.push_back(combinedValue); } return totalEffort; } int main() { int n; std::cin >> n; std::vector<int> lazyValues(n); for (int i = 0; i < n; ++i) { std::cin >> lazyValues[i]; } int minEffort = calculateMinimumEffort(lazyValues); std::cout << minEffort << std::endl; return 0; }