#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<queue>
#define mp make_pair
#define f first
#define s second
#define pb push_back
#define ll long long
#define pii pair<int,int>
#ifndef getchar_unlocked
#define getchar_unlocked getchar
#endif // getchar_unlocked
using namespace std;
const int ma=202000;
int n,t[ma],mak;
int gi(){
int wy=0;
char c;
while(1){
c=getchar_unlocked();
if(c>='0'&&c<='9')break;
}
while(c>='0'&&c<='9'){
//if(c<'0'||c>'9')break;
wy=(wy<<3)+(wy<<1)+int(c-'0');
c=getchar_unlocked();
}
return wy;
}
int main(){
n=gi();
int a;
for(int i=0;i<n;i++){
a=gi();
t[a]++;
mak=max(mak,a);
}
for(int i=0;i<mak;i++){
t[i+1]+=(t[i]>>1);
}
int w=mak;
while(t[mak]>1){
w++;
t[mak]>>=1;
}
printf("%d",w);
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<iostream> #include<stdio.h> #include<vector> #include<algorithm> #include<queue> #define mp make_pair #define f first #define s second #define pb push_back #define ll long long #define pii pair<int,int> #ifndef getchar_unlocked #define getchar_unlocked getchar #endif // getchar_unlocked using namespace std; const int ma=202000; int n,t[ma],mak; int gi(){ int wy=0; char c; while(1){ c=getchar_unlocked(); if(c>='0'&&c<='9')break; } while(c>='0'&&c<='9'){ //if(c<'0'||c>'9')break; wy=(wy<<3)+(wy<<1)+int(c-'0'); c=getchar_unlocked(); } return wy; } int main(){ n=gi(); int a; for(int i=0;i<n;i++){ a=gi(); t[a]++; mak=max(mak,a); } for(int i=0;i<mak;i++){ t[i+1]+=(t[i]>>1); } int w=mak; while(t[mak]>1){ w++; t[mak]>>=1; } printf("%d",w); return 0; } |
English