mfgnik

Untitled

Jun 29th, 2020
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <set>
  3.  
  4. int main() {
  5.     int amount;
  6.     std::cin >> amount;
  7.     std::multiset<int64_t> provinces;
  8.     for (int index = 0; index < amount; ++index) {
  9.         int64_t number;
  10.         std::cin >> number;
  11.         provinces.insert(number);
  12.     }
  13.     int64_t passports = 0;
  14.     while (provinces.size() > 1) {
  15.         int64_t min = *provinces.begin();
  16.         provinces.erase(provinces.begin());
  17.         int64_t second_min = *provinces.begin();
  18.         provinces.erase(provinces.begin());
  19.         passports += min + second_min;
  20.         provinces.insert(min + second_min);
  21.     }  
  22. }
Add Comment
Please, Sign In to add comment