#include <bits/stdc++.h> using namespace std; #define MAX_A 500000 int powers [MAX_A]; int main() { int n, a; vector <int> v; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &a); v.push_back(a); powers[a]++; } for (int i = 0; i < MAX_A; i++) { powers[i+1] += powers[i] / 2; powers[i] %= 2; } for (int i = MAX_A - 1; i >= 0; i--) { if (powers[i] > 0) { printf("%d", 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 29 30 31 32 33 34 35 36 37 38 | #include <bits/stdc++.h> using namespace std; #define MAX_A 500000 int powers [MAX_A]; int main() { int n, a; vector <int> v; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &a); v.push_back(a); powers[a]++; } for (int i = 0; i < MAX_A; i++) { powers[i+1] += powers[i] / 2; powers[i] %= 2; } for (int i = MAX_A - 1; i >= 0; i--) { if (powers[i] > 0) { printf("%d", i); break; } } return 0; } |