1 solutions

  • -4
    @ 2024-7-23 9:51:52
    #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;
    }
    
    • 1

    Information

    ID
    964
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    3
    Tags
    (None)
    # Submissions
    50
    Accepted
    15
    Uploaded By