// PA2017.cpp : Defines the entry point for the console application.
//
#include <iostream>
using namespace std;
const int MAXA = 201739;//+21
int main()
{
ios_base::sync_with_stdio(0);
int an[MAXA];
int n;
for (int i = 0; i < MAXA; i++)
an[i] = 0;
cin >> n;
while (n--)
{
int a;
cin >> a;
an[a]++;
}
int b = 0;
for (int i = 1; i < MAXA; i++)
{
an[i] += an[i - 1] / 2;
if (an[i] > 0)
b = i;
}
cout << b<<endl;
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 | // PA2017.cpp : Defines the entry point for the console application. // #include <iostream> using namespace std; const int MAXA = 201739;//+21 int main() { ios_base::sync_with_stdio(0); int an[MAXA]; int n; for (int i = 0; i < MAXA; i++) an[i] = 0; cin >> n; while (n--) { int a; cin >> a; an[a]++; } int b = 0; for (int i = 1; i < MAXA; i++) { an[i] += an[i - 1] / 2; if (an[i] > 0) b = i; } cout << b<<endl; return 0; } |
English