Cut
Cut
https://ac.nowcoder.com/acm/problem/14291
贪心
这个题目我吐了,居然用long long才能过,简单排序+贪心,我们按照从小到大排序就行,这样下一步操作只是将当前最小的数去掉,这样就能保持最大数了
很简单的题目啦~
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; typedef long long ll; ll a[maxn]; int main() { ll n, sum, ans; while (~scanf("%d", &n)) { sum = 0, ans = 0; for (int i = 1; i <= n; ++i) { scanf("%lld", &a[i]); ans += a[i]; } sort(a + 1, a + n + 1); for (int i = 1; i <= n - 1; ++i) { sum += ans; ans -= a[i]; } printf("%lld\n", sum); } }