Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <set>
- int main() {
- int amount;
- std::cin >> amount;
- std::multiset<int64_t> provinces;
- for (int index = 0; index < amount; ++index) {
- int64_t number;
- std::cin >> number;
- provinces.insert(number);
- }
- int64_t passports = 0;
- while (provinces.size() > 1) {
- int64_t min = *provinces.begin();
- provinces.erase(provinces.begin());
- int64_t second_min = *provinces.begin();
- provinces.erase(provinces.begin());
- passports += min + second_min;
- provinces.insert(min + second_min);
- }
- }
Add Comment
Please, Sign In to add comment