提交时间:2024-08-20 20:31:10
运行 ID: 169940
#include <iostream> #include <vector> using namespace std; // Function to compute the total contribution value long long total_contribution_value(int n, const vector<int>& values) { if (n < 3) { return 0; // Not enough people to form any combination of 3 } // Calculate C(n-1, 2) long long combination_count = (static_cast<long long>(n - 1) * (n - 2)) / 2; // Calculate the total contribution value long long total_value = 0; for (int value : values) { total_value += static_cast<long long>(value) * combination_count; } return total_value; } int main() { int n; cin >> n; vector<int> values(n); for (int i = 0; i < n; ++i) { cin >> values[i]; } cout << total_contribution_value(n, values) << endl; return 0; }