#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
0 ms |
1676 KB |
Output is partially correct |
2 |
Partially correct |
0 ms |
1676 KB |
Output is partially correct |
3 |
Partially correct |
0 ms |
1676 KB |
Output is partially correct |
4 |
Partially correct |
0 ms |
1676 KB |
Output is partially correct |
5 |
Partially correct |
0 ms |
1676 KB |
Output is partially correct |
6 |
Incorrect |
0 ms |
1676 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |