#include <set>
#include <list>
#include <map>
#include <stack>
#include <bitset>
#include <string>
#include <queue>
#include <deque>
#include <cmath>
#include <vector>
#include <climits>
#include <iostream>
#include <algorithm>
#define F first
#define S second
#define MP make_pair
#define PB push_back
using namespace std;
typedef pair < int, int > PII;
typedef long long LL;
typedef vector < int > VI;
typedef vector < PII > VPII;
int n, a, wyn;
int pot[ 1000007 ];
//****************************************************************************************************************************************************************************************************************************************
int main()
{
scanf( "%d", &n );
for( int i = 0; i < n; i++ )
{
scanf( "%d", &a );
pot[ a ]++;
}
for( int i = 0; i < 1000000; i++ )
{
if( pot[ i ] )
wyn = i;
pot[ i + 1 ] += pot[ i ] / 2;
}
printf( "%d", wyn );
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 | #include <set> #include <list> #include <map> #include <stack> #include <bitset> #include <string> #include <queue> #include <deque> #include <cmath> #include <vector> #include <climits> #include <iostream> #include <algorithm> #define F first #define S second #define MP make_pair #define PB push_back using namespace std; typedef pair < int, int > PII; typedef long long LL; typedef vector < int > VI; typedef vector < PII > VPII; int n, a, wyn; int pot[ 1000007 ]; //**************************************************************************************************************************************************************************************************************************************** int main() { scanf( "%d", &n ); for( int i = 0; i < n; i++ ) { scanf( "%d", &a ); pot[ a ]++; } for( int i = 0; i < 1000000; i++ ) { if( pot[ i ] ) wyn = i; pot[ i + 1 ] += pot[ i ] / 2; } printf( "%d", wyn ); return 0; } //**************************************************************************************************************************************************************************************************************************************** |
English