#include <iostream>
#include <queue>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
priority_queue<int,vector<int>,greater<int>>pq; //์ต์ํ
int N; cin >> N;
while (N--) {
int num; cin >> num;
pq.push(num);
}
int sum = 0, ans = 0;
while (pq.size() != 1) {
int temp1 = pq.top(); pq.pop();
int temp2 = pq.top(); pq.pop();
sum = temp1 + temp2;
ans += temp1 * temp2;
pq.push(sum);
}
cout << ans;
}
'Algorithm ๐ง๐ปโ๐ป > ๋ฐฑ์ค(BOJ)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค,c++] 1431๋ฒ - ์๋ฆฌ์ผ ๋ฒํธ (0) | 2021.11.07 |
---|---|
[๋ฐฑ์ค,c++] 14284๋ฒ - ๊ฐ์ ์ด์ด๊ฐ๊ธฐ2 (0) | 2021.11.06 |
[๋ฐฑ์ค,c++] 1427๋ฒ - ์ํธ์ธ์ฌ์ด๋ (0) | 2021.11.06 |
[๋ฐฑ์ค,c++] 1406๋ฒ - ์๋ํฐ (0) | 2021.11.06 |
[๋ฐฑ์ค,c++] 13913๋ฒ - ์จ๋ฐ๊ผญ์ง4 (0) | 2021.11.06 |
[๋ฐฑ์ค,c++] 1389๋ฒ - ์ผ๋น ๋ฒ ์ด์ปจ์ 6๋จ๊ณ ๋ฒ์น (0) | 2021.11.06 |
๋๊ธ