#include <iostream>
#include <queue>
#include <functional>
using namespace std;
int main() {
priority_queue <int, vector<int>, greater<int> > q;
int n;
cin >> n;
for (int i = 0; i < n; i++){
int tmp;
cin >> tmp;
q.push(tmp);
}
int ans = 0;
while (q.size() >= 2) {
int a, b;
a = q.top();
q.pop();
b = q.top();
q.pop();
ans += a * b;
q.push(a + b);
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
- |