Algo-Trian
This commit is contained in:
26
Algorithm/Greedy/P1090 [NOIP 2004 提高组] 合并果子.cpp
Normal file
26
Algorithm/Greedy/P1090 [NOIP 2004 提高组] 合并果子.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include <iostream>
|
||||
#include <queue>
|
||||
using namespace std;
|
||||
int main(){
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
int n;
|
||||
cin >> n;
|
||||
priority_queue<int, vector<int>, greater<int>> q;
|
||||
for(int i = 0; i < n; i++){
|
||||
int a;
|
||||
cin >> a;
|
||||
q.emplace(a);
|
||||
}
|
||||
int value = 0;
|
||||
int min1 = 0, min2 = 0;
|
||||
while(q.size() > 1){
|
||||
min1 = q.top(); q.pop();
|
||||
min2 = q.top(); q.pop();
|
||||
int tmp = min1 + min2;
|
||||
value += tmp;
|
||||
q.emplace(tmp);
|
||||
}
|
||||
cout << value<< endl;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user