Run ID | Author | Problem | Lang | Verdict | Score | Time | Memory | Code Length | Submit Time |
---|---|---|---|---|---|---|---|---|---|
46405 | 杨中琦 | 合并果子 | C++ | Accepted | 100 | 4 MS | 364 KB | 674 | 2022-07-13 13:03:44 |
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<queue> #include<stack> #include<vector> using namespace std; long long n,sum,temp; priority_queue<int>q; int main() { cin>>n; for(int i=0;i<n;i++) { cin>>temp; q.push(-temp); } int k=2; temp=0-q.top(); q.pop(); //cout<<temp<<endl; temp-=q.top(); q.pop(); sum+=temp; //cout<<temp<<endl; q.push(-temp); while(q.empty()!=1) { temp=0-q.top(); q.pop(); //cout<<temp<<endl; //cout<<q.empty()<<endl; if(q.empty()==1) { break; } temp-=q.top(); sum+=temp; q.pop(); q.push(-temp); } cout<<sum; }