#include <iostream> #include <array> using namespace std; using u32 = unsigned int; int main() { u32 n; cin >> n; array<u32, 201718 + 1> coins {0}; for (u32 i = 0; i < n; ++i) { u32 c; cin >> c; coins[c]++; } for (u32 i = 0; i < coins.size() - 1; ++i) { u32 pairs = coins[i] / 2; // each pair can be exchanged for 1 bigger coin coins[i+1] += pairs; } u32 max_val = 0; for (u32 i = 0; i < coins.size(); ++i) { if (coins[i] > 0) max_val = i; } cout << max_val << "\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 30 31 32 33 34 35 36 37 38 | #include <iostream> #include <array> using namespace std; using u32 = unsigned int; int main() { u32 n; cin >> n; array<u32, 201718 + 1> coins {0}; for (u32 i = 0; i < n; ++i) { u32 c; cin >> c; coins[c]++; } for (u32 i = 0; i < coins.size() - 1; ++i) { u32 pairs = coins[i] / 2; // each pair can be exchanged for 1 bigger coin coins[i+1] += pairs; } u32 max_val = 0; for (u32 i = 0; i < coins.size(); ++i) { if (coins[i] > 0) max_val = i; } cout << max_val << "\n"; return 0; } |