#include <algorithm> #include <cstdio> #include <vector> int main(void) { int n; // 201718 + 20 should be enough, but... std::vector<int> coins(300000); int range = 0; int power; // Read the input and remember the highest value std::scanf("%d", &n); while (n--) { std::scanf("%d", &power); ++coins[power]; range = ::std::max(range, power); } // Get the highest achievable power int max_pow = 0; int rem = 0; for (; max_pow < range || (rem + coins[max_pow]) > 1; ++max_pow) { rem = (rem + coins[max_pow]) / 2; } std::printf("%d\n", max_pow); 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 | #include <algorithm> #include <cstdio> #include <vector> int main(void) { int n; // 201718 + 20 should be enough, but... std::vector<int> coins(300000); int range = 0; int power; // Read the input and remember the highest value std::scanf("%d", &n); while (n--) { std::scanf("%d", &power); ++coins[power]; range = ::std::max(range, power); } // Get the highest achievable power int max_pow = 0; int rem = 0; for (; max_pow < range || (rem + coins[max_pow]) > 1; ++max_pow) { rem = (rem + coins[max_pow]) / 2; } std::printf("%d\n", max_pow); return 0; } |