提交时间:2023-08-23 10:52:06

运行 ID: 99582

#include<bits/stdc++.h> using namespace std; int a[10005], b[10005]; int main(){ int n, sum = 0; cin >> n; for (int i = 1; i <= n; i++){ cin >> a[i]; } sort(a + 1, a + 1 + n); for (int i = 1; i <= n; i++){ int x = a[i] + a[i + 1]; sum += a[i] + a[i + 1]; a[i + 1] = x; if (i + 1 == n){ break; } } cout << sum; return 0; }