#include <cstdio> using namespace std; const int MAXN = 10;// 3e5; int A[MAXN];//={0}; int n, x; int main() { for (int i = 0; i < MAXN; i++) A[i] = 0; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &x); A[x]++; } for (int i = 1; i < MAXN; i++) A[i] += A[i - 1] / 2; for (int i = MAXN - 1; i >= 0; i--) { if (A[i] != 0) { printf("%d\n", i); break; } } 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 | #include <cstdio> using namespace std; const int MAXN = 10;// 3e5; int A[MAXN];//={0}; int n, x; int main() { for (int i = 0; i < MAXN; i++) A[i] = 0; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &x); A[x]++; } for (int i = 1; i < MAXN; i++) A[i] += A[i - 1] / 2; for (int i = MAXN - 1; i >= 0; i--) { if (A[i] != 0) { printf("%d\n", i); break; } } return 0; } |