fork(1) download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. priority_queue<long long>q;
  4.  
  5. int main(){
  6. ios_base::sync_with_stdio(0);
  7. cin.tie(0);
  8. long long n,a,b,w=0;
  9. cin>>n;
  10. for(int i=0;i<n;i++){
  11. cin>>a;
  12. q.push(a*-1);
  13. }
  14. while(q.size()>=2){
  15. a=q.top();
  16. q.pop();
  17. b=q.top();
  18. q.pop();
  19. w-=a+b;
  20. q.push(a+b);
  21. }
  22. cout<<w;
  23. }
Success #stdin #stdout 0.01s 5284KB
stdin
3
2 3 6
stdout
16