求助
  • 板块灌水区
  • 楼主first_king
  • 当前回复5
  • 已保存回复5
  • 发布时间2023/4/22 14:22
  • 上次更新2023/10/23 17:48:32
查看原帖
求助
995980
first_king楼主2023/4/22 14:22
#include <bits/stdc++.h>
using namespace std;
priority_queue<int,vector<int >,greater<int > > b;
inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
        x=x*10+ch-'0',ch=getchar();
    return x*f;
}
inline void write(int x){
    if(x<0)
        putchar('-'),x=-x;
    if(x>9)
        write(x/10);
    putchar(x%10+'0');
    return ;
}
int main(){
	std::ios::sync_with_stdio(false);
    int n,a[10001]={};
    n=read();
    for(int i=1;i<=n;i++){
    	a[i]=read();
    	b.push(a[i]);
	}
	int sum=0;
	while(b.size()!=1){
		for(int i=1;i<=2;i++){
			sum+=b.top();
			b.pop();
		}
		b.push(sum);
	}
	cout<<sum;
    return 0;
}
2023/4/22 14:22
加载中...