#include <bits/stdc++.h> #define f first #define s second #define MP make_pair #define PB push_back #define LL long long #define pii pair<int,int> #define pll pair<LL,LL> #define ALL(V) V.begin(),V.end() #define f1(a,b) for(int a=1;a<=b;a++) #define f0(a,b) for(int a=0;a<b;a++) #define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define endl "\n" using namespace std; const int N=1e6+69; int n,a,t[N],w; int32_t main(void) { scanf("%d", &n); f0(i,n) { scanf("%d", &a); t[a]++; } f0(i,N-3) { if(t[i]!=0) w=i; t[i+1]+=(t[i]/2); } printf("%d\n", w); }
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 | #include <bits/stdc++.h> #define f first #define s second #define MP make_pair #define PB push_back #define LL long long #define pii pair<int,int> #define pll pair<LL,LL> #define ALL(V) V.begin(),V.end() #define f1(a,b) for(int a=1;a<=b;a++) #define f0(a,b) for(int a=0;a<b;a++) #define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define endl "\n" using namespace std; const int N=1e6+69; int n,a,t[N],w; int32_t main(void) { scanf("%d", &n); f0(i,n) { scanf("%d", &a); t[a]++; } f0(i,N-3) { if(t[i]!=0) w=i; t[i+1]+=(t[i]/2); } printf("%d\n", w); } |