3 条题解
-
1韩梓欣 LV 4 @ 2024-12-02 21:06:11
#include<bits/stdc++.h>
using namespace std;long long n,a[100000],sum=0,sum1=0;int main()
{
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i];
sort(a+1,a+n+1);
for(int i=2;i<=n;i++)
a[i]+=a[i-1],sum+=a[i],sort(a+i,a+n+1);cout<<sum+sum1;
return 0;
}
//服了,为什么要用到结合体!!! -
02022-09-25 09:13:56@
#include<bits/stdc++.h> using namespace std;long long n,a[100000],sum=0,sum1=0; int main() { cin>>n; for(int i=1;i<=n;i++) cin>>a[i]; sort(a+1,a+n+1); for(int i=2;i<=n;i++) a[i]+=a[i-1],sum+=a[i],sort(a+i,a+n+1); cout<<sum+sum1; return 0; }
-
-12021-12-16 20:35:37@
#include <bits/stdc++.h> using namespace std; int main() { int num, i,x = 0,ans = 0; priority_queue<int,vector<int>, greater<int> >p; //greater让根节点最小 cin >> num; for (i = 0;i < num;i++) { cin >> x; p.push(x); //放入数字 } while (p.size() != 1) { x = p.top(); p.pop(); x += p.top(); //将最大的两个相加 p.pop(); p.push(x); //将和放入队列 ans += x; } cout << ans << endl; //输出答案 }
- 1