'commit'
This commit is contained in:
37
TangDou/KaoShi/合并麦子.cpp
Normal file
37
TangDou/KaoShi/合并麦子.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
// OJ地址
|
||||
// https://www.acwing.com/problem/content/150/
|
||||
|
||||
// 黄海题解
|
||||
// https://www.cnblogs.com/littlehb/p/15488791.html
|
||||
|
||||
//小顶堆
|
||||
priority_queue<int, vector<int>, greater<int>> q;
|
||||
|
||||
int res;
|
||||
|
||||
int main() {
|
||||
int n;
|
||||
cin >> n;
|
||||
|
||||
while (n--) {
|
||||
int x;
|
||||
cin >> x;
|
||||
q.push(x);
|
||||
}
|
||||
|
||||
while (q.size() > 1) {
|
||||
int a = q.top();
|
||||
q.pop();
|
||||
int b = q.top();
|
||||
q.pop();
|
||||
res += a + b;
|
||||
q.push(a + b);
|
||||
}
|
||||
|
||||
printf("%d\n", res);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user