#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { unsigned long n; unsigned long t; cin >> n; if(n==1){ cin >> n; cout << n; return 0; } vector<unsigned long> a(n); for (unsigned long i=0; i<n; i++) { cin >> t; a[i] = t; } sort(a.rbegin(), a.rend()); long counter = 1; t = a[n-1]; for(long i=n-2; i>=0; i--){ if(t != a[i]){ counter = counter/2; if(counter > 0) { t++; i++; } else { t = a[i]; counter++; } } else{ counter++; } } cout << t + counter/2; 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 48 49 | #include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { unsigned long n; unsigned long t; cin >> n; if(n==1){ cin >> n; cout << n; return 0; } vector<unsigned long> a(n); for (unsigned long i=0; i<n; i++) { cin >> t; a[i] = t; } sort(a.rbegin(), a.rend()); long counter = 1; t = a[n-1]; for(long i=n-2; i>=0; i--){ if(t != a[i]){ counter = counter/2; if(counter > 0) { t++; i++; } else { t = a[i]; counter++; } } else{ counter++; } } cout << t + counter/2; return 0; } |