#include <iostream>
#include <vector>
#include <algorithm>
int main()
{
int n;
std::cin >> n;
std::vector<int> coins(n);
for ( auto &coin : coins)
{
std::cin >> coin;
}
std::sort(coins.begin(), coins.end());
while (coins.size() != 1)
{
const auto first = coins.front();
coins.erase(coins.begin());
const auto second = coins.front();
if (first == second)
{
coins.erase(coins.begin());
coins.insert(coins.begin(), first+1);
std::sort(coins.begin(), coins.end());
}
}
std::cout << coins.front() << "\n";
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | #include <iostream> #include <vector> #include <algorithm> int main() { int n; std::cin >> n; std::vector<int> coins(n); for ( auto &coin : coins) { std::cin >> coin; } std::sort(coins.begin(), coins.end()); while (coins.size() != 1) { const auto first = coins.front(); coins.erase(coins.begin()); const auto second = coins.front(); if (first == second) { coins.erase(coins.begin()); coins.insert(coins.begin(), first+1); std::sort(coins.begin(), coins.end()); } } std::cout << coins.front() << "\n"; return 0; } |
English