Algorithm-Renewed
This commit is contained in:
23
Algorithm/Greedy/UVa10954AddAll.cpp
Normal file
23
Algorithm/Greedy/UVa10954AddAll.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#include <iostream>
|
||||
#include <queue>
|
||||
using namespace std;
|
||||
int main(){
|
||||
long long sum = 0;
|
||||
priority_queue<int, vector<int>, greater<int>> q;
|
||||
int n;
|
||||
cin >> n;
|
||||
for(int i = 0; i < n; i++){
|
||||
int tmp;
|
||||
cin >> tmp;
|
||||
q.push(tmp);
|
||||
}
|
||||
while(q.size() > 1){
|
||||
int a = q.top();q.pop();
|
||||
int b = q.top();q.pop();
|
||||
int tmp = a + b;
|
||||
sum += tmp;
|
||||
q.push(tmp);
|
||||
}
|
||||
cout << sum << endl;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user