Submission #9759

#TimeUsernameProblemLanguageResultExecution timeMemory
9759silasUniting (kriii2_U)C++98
0 / 4
0 ms1676 KiB
#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 timeMemoryGrader output
Fetching results...