#include <iostream> using namespace std; int main(){ int n, t, m; int a[230000]; m = -1; cin >> n; for(int i = 0; i < 230000; i++) a[i] = 0; for(int i = 0; i < n; i++){ cin >> t; a[t]++; } for(int i = 1; i < 230000; i++){ a[i] += a[i - 1]/2; if(a[i] > 0) m = i; } cout << m << endl; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #include <iostream> using namespace std; int main(){ int n, t, m; int a[230000]; m = -1; cin >> n; for(int i = 0; i < 230000; i++) a[i] = 0; for(int i = 0; i < n; i++){ cin >> t; a[t]++; } for(int i = 1; i < 230000; i++){ a[i] += a[i - 1]/2; if(a[i] > 0) m = i; } cout << m << endl; } |