1 solutions
-
1
#include<bits/stdc++.h> using namespace std; int main() { int n; cin>>n; priority_queue<int,vector<int>,greater<int>> q; for(int i=1;i<=n;i++) { int x; cin>>x; q.push(x); } int res=0; while(q.size()>1) { int a=q.top();q.pop(); int b=q.top();q.pop(); res+=a+b; q.push(a+b); } cout<<res; return 0; }
Information
- ID
- 1017
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 5
- Tags
- (None)
- # Submissions
- 20
- Accepted
- 13
- Uploaded By