Submission #9762

#TimeUsernameProblemLanguageResultExecution timeMemory
9762silasUniting (kriii2_U)C++98
0 / 4
20 ms1676 KiB
#include <iostream> #include <queue> #include <functional> #include <vector> #include <algorithm> using namespace std; int main() { vector<int> arr; int cost = 0; // 비용의 합의 최솟값 int num, temp; // num : 부서의 수 cin >> num; for (int i = 0 ; i < num; i++) { cin >> temp; arr.push_back(temp); } sort(arr.begin(), arr.end()); while (arr.size() > 1) { cost += arr[0] * arr[arr.size() - 1]; int tmp = arr[0] + arr[arr.size() - 1]; arr.erase(arr.begin()); arr.pop_back(); arr.push_back(tmp); sort(arr.begin(), arr.end()); } cout << cost << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...