#include <iostream>
using namespace std;
int potegi[301740];
int main(){
int a,b,bmax=0;
cin>>a;
for(int i=0; i < a; i++){
cin>>b;
potegi[b]++;
if(b > bmax) bmax = b;
}
int pom = 0;
int i=0;
for(; i<=bmax or pom>1; i++){
while(pom>1){
pom-=2; potegi[i]++;
}
if(pom==1) pom--;
pom=potegi[i];
}
cout<<i-1;
}
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 | #include <iostream> using namespace std; int potegi[301740]; int main(){ int a,b,bmax=0; cin>>a; for(int i=0; i < a; i++){ cin>>b; potegi[b]++; if(b > bmax) bmax = b; } int pom = 0; int i=0; for(; i<=bmax or pom>1; i++){ while(pom>1){ pom-=2; potegi[i]++; } if(pom==1) pom--; pom=potegi[i]; } cout<<i-1; } |
English