'commit'
This commit is contained in:
16
C++专题课程/NOIP算法总结/贪心/合并果子/P1090.cpp
Normal file
16
C++专题课程/NOIP算法总结/贪心/合并果子/P1090.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#include<bits/stdc++.h>
|
||||
using namespace std;
|
||||
int n,x,ans;
|
||||
priority_queue<int,vector<int>,greater<int> >q;
|
||||
int main(){
|
||||
cin>>n;
|
||||
for(int i=1;i<=n;i++) cin>>x,q.push(x);
|
||||
while(q.size()>=2){
|
||||
int a=q.top(); q.pop();
|
||||
int b=q.top(); q.pop();
|
||||
ans+=a+b;
|
||||
q.push(a+b);
|
||||
}
|
||||
cout<<ans<<endl;
|
||||
return 0;
|
||||
}
|
||||
1
C++专题课程/NOIP算法总结/贪心/合并果子/题目链接.txt
Normal file
1
C++专题课程/NOIP算法总结/贪心/合并果子/题目链接.txt
Normal file
@@ -0,0 +1 @@
|
||||
https://www.luogu.org/problem/P1090
|
||||
Reference in New Issue
Block a user