# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
9759 | silas | Uniting (kriii2_U) | C++98 | 0 ms | 1676 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <queue>
#include <functional>
using namespace std;
int main() {
priority_queue<int, vector<int> > max_heap;
priority_queue <int, vector<int>, greater<int> > min_heap;
int cost = 0; // 비용의 합의 최솟값
int num_busu = 0;
int num, temp; // num : 부서의 수
cin >> num;
for (int i = 0 ; i < num; i++) {
cin >> temp;
max_heap.push(temp);
min_heap.push(temp);
num_busu++;
}
while (num_busu > 1) {
cost += max_heap.top() * min_heap.top();
int tmp = max_heap.top() + min_heap.top();
min_heap.pop(); max_heap.pop();
max_heap.push(tmp); min_heap.push(tmp);
num_busu--;
}
cout << cost << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |