#include<bits/stdc++.h> using namespace std; int t[210000]; int main() { int n; scanf("%d", &n); for(int i = 0 ; i < n ; i++) { int k; scanf("%d", &k); t[k]++; } int res = 0; for(int i = 1 ; i < 210000 ; i++) { if(t[i] != 0) { res = i; t[i+1] += (t[i]/2); } } printf("%d\n", res); }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #include<bits/stdc++.h> using namespace std; int t[210000]; int main() { int n; scanf("%d", &n); for(int i = 0 ; i < n ; i++) { int k; scanf("%d", &k); t[k]++; } int res = 0; for(int i = 1 ; i < 210000 ; i++) { if(t[i] != 0) { res = i; t[i+1] += (t[i]/2); } } printf("%d\n", res); } |