#include<iostream> using namespace std; //************************************************************************************************************************** int wartosc[300000]; //************************************************************************************************************************** int main() { int a,n,bufor,max = -1; int licz = 1; cin >> n; for (int i = 0; i < n; i++) { cin >> a; wartosc[a]++; } for (int i = 0; i < 300000; i++) { if (wartosc[i] >= 2) { bufor = wartosc[i] / 2; wartosc[i] -= bufor * 2; wartosc[i + 1] += bufor; } } for (int i = 0; i < 300000; i++) { if (wartosc[i] == 1) { max = i; } } cout << max << endl; 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 | #include<iostream> using namespace std; //************************************************************************************************************************** int wartosc[300000]; //************************************************************************************************************************** int main() { int a,n,bufor,max = -1; int licz = 1; cin >> n; for (int i = 0; i < n; i++) { cin >> a; wartosc[a]++; } for (int i = 0; i < 300000; i++) { if (wartosc[i] >= 2) { bufor = wartosc[i] / 2; wartosc[i] -= bufor * 2; wartosc[i + 1] += bufor; } } for (int i = 0; i < 300000; i++) { if (wartosc[i] == 1) { max = i; } } cout << max << endl; return 0; } //************************************************************************************************************************** |