#include<bits/stdc++.h>
using namespace std;
int zl[1000005],n,a,ind,maxim;
priority_queue<int,vector<int>,greater<int> >kolejka;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie();
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a;
if(zl[a]==0)kolejka.push(a);
zl[a]++;
}
while(!kolejka.empty())
{
int w=kolejka.top();
int ile=zl[w];
kolejka.pop();
if(ile>1)
{
if(zl[w+1]==0)
{
kolejka.push(w+1);
}
zl[w+1]+=ile/2;
}
maxim=max(maxim,kolejka.top());
}
cout<<maxim;
}
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 | #include<bits/stdc++.h> using namespace std; int zl[1000005],n,a,ind,maxim; priority_queue<int,vector<int>,greater<int> >kolejka; int main() { ios_base::sync_with_stdio(0); cin.tie(); cin>>n; for(int i=1;i<=n;i++) { cin>>a; if(zl[a]==0)kolejka.push(a); zl[a]++; } while(!kolejka.empty()) { int w=kolejka.top(); int ile=zl[w]; kolejka.pop(); if(ile>1) { if(zl[w+1]==0) { kolejka.push(w+1); } zl[w+1]+=ile/2; } maxim=max(maxim,kolejka.top()); } cout<<maxim; } |
English