Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
134343 | 梁颢城 | 紧急集合 | C++ | 通过 | 100 | 2 MS | 484 KB | 526 | 2024-03-02 15:39:44 |
#include<bits/stdc++.h> #define int long long using namespace std; signed main(){ ios::sync_with_stdio(0); cin.tie(0); priority_queue<int,vector<int>, greater<int>>q; int n; cin >> n; for(int i = 1;i <= n;i++){ int x; cin >> x; q.push(x); } int ans = 0; for(int i = 1;i < n;i++){ int a = q.top(); q.pop(); int b = q.top(); q.pop(); ans+=a+b; q.push(a+b); } cout << ans; return 0; }