#include <algorithm>
#include <stdint.h>
#include <vector>
#include <cstdio>
#include <map>
using namespace std;
int main(){
int n, a;
map<int, uint64_t> M;
scanf("%d", &n);
for(int i=0; i<n; ++i){
scanf("%d", &a);
M[a]+=1;
}
while (M.size() > 1 || M.begin()->second > 1) {
M[M.begin()->first + 1] += M.begin()->second >> 1;
M.erase(M.begin());
}
printf("%d", M.begin()->first);
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #include <algorithm> #include <stdint.h> #include <vector> #include <cstdio> #include <map> using namespace std; int main(){ int n, a; map<int, uint64_t> M; scanf("%d", &n); for(int i=0; i<n; ++i){ scanf("%d", &a); M[a]+=1; } while (M.size() > 1 || M.begin()->second > 1) { M[M.begin()->first + 1] += M.begin()->second >> 1; M.erase(M.begin()); } printf("%d", M.begin()->first); } |
English