#include<cstdio>
const int N = 300000;
int bits[N];
int n;
int* t;
int solution;
void input() {
scanf("%d", &n);
t = new int[n];
for (int i = 0; i < n; i++) {
scanf("%d", t + i);
}
}
void setBits() {
for (int i = 0; i < n; i++) {
bits[t[i]]++;
}
}
void carry() {
int carryOver = 0;
for (int i = 0; i < N; i++) {
carryOver += bits[i];
bits[i] = carryOver % 2;
carryOver /= 2;
}
}
void findSolution() {
for (int i = N - 1; i >= 0; i--) {
if (bits[i] != 0) {
solution = i;
return;
}
}
}
void solve() {
setBits();
carry();
findSolution();
}
void printSolution() {
printf("%d\n", solution);
}
int main(int argc, char ** argv) {
input();
solve();
printSolution();
}
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | #include<cstdio> const int N = 300000; int bits[N]; int n; int* t; int solution; void input() { scanf("%d", &n); t = new int[n]; for (int i = 0; i < n; i++) { scanf("%d", t + i); } } void setBits() { for (int i = 0; i < n; i++) { bits[t[i]]++; } } void carry() { int carryOver = 0; for (int i = 0; i < N; i++) { carryOver += bits[i]; bits[i] = carryOver % 2; carryOver /= 2; } } void findSolution() { for (int i = N - 1; i >= 0; i--) { if (bits[i] != 0) { solution = i; return; } } } void solve() { setBits(); carry(); findSolution(); } void printSolution() { printf("%d\n", solution); } int main(int argc, char ** argv) { input(); solve(); printSolution(); } |
English