#include <bits/stdc++.h> using namespace std; int n, x, out; int tab[300010]; int main(){ cin>>n; for(int i=0; i<n; i++){ cin>>x; tab[x]++; } for(int i=0; i<300000; i++){ if(tab[i]>0)out=i; tab[i+1]+=(tab[i]/2); } cout<<out; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | #include <bits/stdc++.h> using namespace std; int n, x, out; int tab[300010]; int main(){ cin>>n; for(int i=0; i<n; i++){ cin>>x; tab[x]++; } for(int i=0; i<300000; i++){ if(tab[i]>0)out=i; tab[i+1]+=(tab[i]/2); } cout<<out; } |