# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
9762 | silas | Uniting (kriii2_U) | C++98 | 20 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>
#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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |