#include<bits/stdc++.h> using namespace std; #define REP(i, M) for(int i = 0; i < M; i++) #define R(p, k) for(int i = p; i <= k; i++) #define RI(j, p, k) for(int j = p; j <= k; j++) #define PB push_back #define FI first #define SE second #define LL long long #define DEB 1 #if DEB #define CEN cerr << endl; #define CEL(a) cerr << #a << ": " << a << " "; #define CES(s) cerr << s << endl; #else #define CEN #define CEL(a) #define CES(s) #endif //const int MN = 10; const int MN = 1000 * 1000; int kub[MN]; int n, a, res; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; for(int i = 0; i<n; i++){ cin >> a; kub[a]++; } for(int i = 0; i + 1 < MN; i++){ //cerr << i << " " << kub[i] << endl; if(kub[i] > 0) res = i; kub[i + 1] += kub[i]/2; } cout << res << 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 46 47 | #include<bits/stdc++.h> using namespace std; #define REP(i, M) for(int i = 0; i < M; i++) #define R(p, k) for(int i = p; i <= k; i++) #define RI(j, p, k) for(int j = p; j <= k; j++) #define PB push_back #define FI first #define SE second #define LL long long #define DEB 1 #if DEB #define CEN cerr << endl; #define CEL(a) cerr << #a << ": " << a << " "; #define CES(s) cerr << s << endl; #else #define CEN #define CEL(a) #define CES(s) #endif //const int MN = 10; const int MN = 1000 * 1000; int kub[MN]; int n, a, res; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; for(int i = 0; i<n; i++){ cin >> a; kub[a]++; } for(int i = 0; i + 1 < MN; i++){ //cerr << i << " " << kub[i] << endl; if(kub[i] > 0) res = i; kub[i + 1] += kub[i]/2; } cout << res << endl; return 0; } |