#include <iostream> #include <algorithm> int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); unsigned n; std::cin >> n; const int SIZE = 201720 + 50; auto * coins = new unsigned[SIZE]; std::fill(coins, coins + SIZE, 0); for (int i = 0; i < n; ++i) { unsigned long long coin; std::cin >> coin; coins[coin]++; } for (int i = 0; i < SIZE - 1; i++) coins[i + 1] += coins[i] / 2; for (int i = SIZE - 1; i >= 0; i--) { if (coins[i]) { std::cout << i << std::endl; break; } } }
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 | #include <iostream> #include <algorithm> int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); unsigned n; std::cin >> n; const int SIZE = 201720 + 50; auto * coins = new unsigned[SIZE]; std::fill(coins, coins + SIZE, 0); for (int i = 0; i < n; ++i) { unsigned long long coin; std::cin >> coin; coins[coin]++; } for (int i = 0; i < SIZE - 1; i++) coins[i + 1] += coins[i] / 2; for (int i = SIZE - 1; i >= 0; i--) { if (coins[i]) { std::cout << i << std::endl; break; } } } |