求助:最后一个大测试点TLE,其他全AC
查看原帖
求助:最后一个大测试点TLE,其他全AC
1023793
yaodiguoan楼主2023/11/5 09:07
#include <algorithm> //STL 通用算法
#include <queue> //STL 队列容器
#include <iostream>
#define fo(i,j,n,k) for(int (i)=(j);(i)<=(n);(i)+=(k))
using namespace std;
const int upint=1e6+10;
const double downdouble=1e-6;
priority_queue<long long,vector<long long >,greater<long long> >q;//升序
//priority_queue<int,vector<int>,less<int> >q;//降序
//priority_queue<int>::iterator it;
typedef long long ll;
typedef double dp;
ll n,a,cnt=0;

int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	scanf("%lld",&n);
	fo(i,1,n,1){
		scanf("%lld",&a);
		q.push(a);
	}
	while(q.size()>=2){
		ll a=q.top();
		q.pop();
		ll b=q.top();
		q.pop();
		cnt+=a+b;
		q.push(a+b);
	}
	printf("%lld",cnt);
	return 0;
}


2023/11/5 09:07
加载中...