#include <bits/stdc++.h> #define FOR(i,b,e) for(int i=(b); i <= (e); ++i) #define FORD(i,b,e) for(int i=(b); i >= (e); --i) #define SIZE(c) (int) (c).size() #define FORE(i,c) FOR(i,0,SIZE(c)-1) #define FORDE(i,c) FORD(i,SIZE(c)-1,0) #define pb push_back #define mp make_pair #define st first #define nd second using namespace std; const int N = 300000; int cnt[N]; /*************************************************************************/ int main() { ios_base::sync_with_stdio(0); int n; cin >> n; while (n--) { int x; cin >> x; cnt[x]++; } FOR(i,0,N-2) { cnt[i+1] += cnt[i] / 2; cnt[i] %= 2; } int ans = N-1; while (cnt[ans] == 0) ans--; cout << ans; 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 <bits/stdc++.h> #define FOR(i,b,e) for(int i=(b); i <= (e); ++i) #define FORD(i,b,e) for(int i=(b); i >= (e); --i) #define SIZE(c) (int) (c).size() #define FORE(i,c) FOR(i,0,SIZE(c)-1) #define FORDE(i,c) FORD(i,SIZE(c)-1,0) #define pb push_back #define mp make_pair #define st first #define nd second using namespace std; const int N = 300000; int cnt[N]; /*************************************************************************/ int main() { ios_base::sync_with_stdio(0); int n; cin >> n; while (n--) { int x; cin >> x; cnt[x]++; } FOR(i,0,N-2) { cnt[i+1] += cnt[i] / 2; cnt[i] %= 2; } int ans = N-1; while (cnt[ans] == 0) ans--; cout << ans; return 0; } /*************************************************************************/ |