2 条题解

  • 0
    @ 2024-10-21 0:26:27
    #include<bits/stdc++.h>
    using namespace std;
    const int N=1e5+10;
    typedef long long  LL;
    
    int main()
    {
    	int n;
    	cin>>n;
    	priority_queue<int,vector<int>,less<int>> q;//大根堆
    	
    	for(int i=0;i<n;i++)
    	{
    		int x;
    		cin>>x;
    		q.push(x);
    	}
    	
    	LL sum=0;
    	LL cnt=0;
    	
    	cnt=q.top();
    	q.pop();
    	while(q.size()!=0)
    	{
    		cnt+=q.top();//计算一个每次计算叠加的值
    		sum+=cnt;//计算答案
    		q.pop();
    	}
    	
    	cout<<sum;
    	return 0;	
    }
    

    信息

    ID
    118
    时间
    1000ms
    内存
    256MiB
    难度
    3
    标签
    递交数
    46
    已通过
    26
    上传者