#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;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
8 ms |
1676 KB |
Output is partially correct |
6 |
Incorrect |
20 ms |
1676 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |