#include<iostream>
#include<cmath>
using namespace std;
int t[202718];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int a,tmp,wynik=1;
cin>>a;
for(int i=0;i<a;i++)
{
cin>>tmp;
t[tmp]++;
while(t[tmp]>=2)
{
t[tmp+1]++;
t[tmp]-=2;
wynik=max(wynik,tmp+1);
tmp++;
}
wynik=max(wynik,tmp);
}
cout<<wynik;
}
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 | #include<iostream> #include<cmath> using namespace std; int t[202718]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int a,tmp,wynik=1; cin>>a; for(int i=0;i<a;i++) { cin>>tmp; t[tmp]++; while(t[tmp]>=2) { t[tmp+1]++; t[tmp]-=2; wynik=max(wynik,tmp+1); tmp++; } wynik=max(wynik,tmp); } cout<<wynik; } |
English