#include <iostream>
using namespace std;
int main(){
int n;
cin >> n;
int tab[n];
for(int i = 0; i < n; i++)
cin >> tab[i];
const int leng = 201718 + 1;
int aux[leng];
for(int j = 0; j < leng; j++)
aux[j] = 0;
int h = 0;
for(int k = 0; k < n; k++)
{
h = tab[k];
aux[h] += 1;
}
int end = leng - 1;
bool b = 1;
for(int p = leng - 1; (p >= 0) && b; p--)
{
if(aux[p] != 0)
{
b = 0;
end = p;
}
}
if(b == 1)
end = 0;
bool stop2 = 0;
int index = 0;
int res = 0;
bool stop = 1;
while(stop)
{
res = res / 2;
if(index < end)
res += aux[index];
else if(index == end)
{
res += aux[index];
if(res <= 1)
stop2 = 1;
}
else
stop2 = 1;
if(stop2 && (res <= 1))
stop = 0;
else
index++;
}
cout << index;
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | #include <iostream> using namespace std; int main(){ int n; cin >> n; int tab[n]; for(int i = 0; i < n; i++) cin >> tab[i]; const int leng = 201718 + 1; int aux[leng]; for(int j = 0; j < leng; j++) aux[j] = 0; int h = 0; for(int k = 0; k < n; k++) { h = tab[k]; aux[h] += 1; } int end = leng - 1; bool b = 1; for(int p = leng - 1; (p >= 0) && b; p--) { if(aux[p] != 0) { b = 0; end = p; } } if(b == 1) end = 0; bool stop2 = 0; int index = 0; int res = 0; bool stop = 1; while(stop) { res = res / 2; if(index < end) res += aux[index]; else if(index == end) { res += aux[index]; if(res <= 1) stop2 = 1; } else stop2 = 1; if(stop2 && (res <= 1)) stop = 0; else index++; } cout << index; return 0; } |
English