#include <iostream>
#include <map>
#include <set>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
int n;
cin>>n;
set <int> kol;
map <int, int> mapa;
map<int, int>::iterator itmap;
set<int>::iterator itset;
set<int>::iterator itset2;
int a;
for(int i=0;i < n; i++){
cin>>a;
itset = kol.find(a);
if(itset == kol.end()){
kol.insert(a);
mapa[a] = 1;
}
else{
mapa[a]++;
}
}
itset = kol.begin();
while(itset != kol.end()){
if(kol.find(*itset + 1) != kol.end()){
if(mapa[*itset] >= 2) {
mapa[*itset + 1] += (mapa[*itset]) / 2;
}
}
else{
if(mapa[*itset] >= 2) {
kol.insert(*itset + 1);
mapa[*itset + 1] = (mapa[*itset]) / 2;
}
}
itset = kol.upper_bound(*itset);
}
itset = kol.end();
itset --;
cout<<*itset<<"\n";
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 | #include <iostream> #include <map> #include <set> using namespace std; int main() { ios_base::sync_with_stdio(0); int n; cin>>n; set <int> kol; map <int, int> mapa; map<int, int>::iterator itmap; set<int>::iterator itset; set<int>::iterator itset2; int a; for(int i=0;i < n; i++){ cin>>a; itset = kol.find(a); if(itset == kol.end()){ kol.insert(a); mapa[a] = 1; } else{ mapa[a]++; } } itset = kol.begin(); while(itset != kol.end()){ if(kol.find(*itset + 1) != kol.end()){ if(mapa[*itset] >= 2) { mapa[*itset + 1] += (mapa[*itset]) / 2; } } else{ if(mapa[*itset] >= 2) { kol.insert(*itset + 1); mapa[*itset + 1] = (mapa[*itset]) / 2; } } itset = kol.upper_bound(*itset); } itset = kol.end(); itset --; cout<<*itset<<"\n"; return 0; } |
English