1 条题解
-
0
C++ :
#include<bits/stdc++.h> #define INF 0x3f3f3f3f #define inf 0x7FFFFFFF #define LL long long #define endl '\n' using namespace std; long long read(){ long long q=0,w=1; char ch=getchar(); while(ch>'9' || ch<'0'){if(ch=='-')w=-1;ch=getchar();} while(ch>='0'&&ch<='9'){q=q*10+(ch-'0');ch=getchar();} return q*w; } void write(LL x){ if(x<0){putchar('-');x=(-x);} if(x>9)write(x/10); putchar('0'+x%10); } void writeln(LL x){write(x);puts("");} void writecs(LL x){write(x);putchar(' ');} const long long N = 1e5+95; long long n,a[N],ans; priority_queue<LL,vector<LL>,greater<LL> >p; int main(){ n=read(); for(LL i=1;i<=n;i++)a[i]=read(); for(LL i=1;i<=n;i++)p.push(a[i]); for(LL i=1;i<n;i++){ LL x=p.top();p.pop(); LL y=p.top();p.pop(); ans+=x;ans+=y;p.push(x+y); } writeln(ans); return 0; }
- 1
信息
- ID
- 912
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者