Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

a guest Apr 10th, 2020 134 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <queue>
  3. #include <vector>
  4.  
  5. std::priority_queue<int, std::vector<int>, std::greater<int>> get_nums(std::vector<int> &v){
  6.     std::priority_queue<int, std::vector<int>, std::greater<int>> q;
  7.     for(int i:v) {
  8.         q.push(i);
  9.     }
  10.     return q;
  11. }
  12.  
  13. int main() {
  14.     int n = 0;
  15.     int result = 0;
  16.     std::vector<int> nums;
  17.     std::cin >> n;
  18.     for (int i = 0; i < n; ++i) {
  19.         int a;
  20.         std::cin >> a;
  21.         nums.push_back(a);
  22.     }
  23.     std::priority_queue<int, std::vector<int>, std::greater<int>> q = get_nums(nums);
  24.     for(int i = 0; i < n - 1; ++i) {
  25.         int a = q.top();
  26.         q.pop();
  27.         int b = q.top();
  28.         q.pop();
  29.         q.emplace(a * b);
  30.         result += a * b;
  31.     }
  32.     std::cout << result;
  33.     return 0;
  34. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top