#include <bits/stdc++.h>
using namespace std;
#ifndef _WIN32
#define getchar getchar_unlocked
#endif
#define MP make_pair
#define PB push_back
#define ST first
#define ND second
typedef long long int LLI;
typedef unsigned long long int LLU;
typedef long double LD;
typedef pair<int, int> pii;
typedef pair<long long int, long long int> pll;
typedef vector<int> vi;
template<class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";}
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
while(*sdbg!=',') cerr<<*sdbg++;
cerr<<"="<<h<<",";
_dbg(sdbg+1, a...);
}
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int kek[500007];
int32_t main()
{
int n; scanf("%d", &n);
for(int i = 1; i <= n; ++i){ int x; scanf("%d", &x); ++kek[x]; }
int odp = 0;
for(int i = 0; i < 500006; ++i){
if(kek[i] > 0) odp = max(odp, i);
kek[i + 1] += kek[i] / 2;
}
printf("%d", odp);
}
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 | #include <bits/stdc++.h> using namespace std; #ifndef _WIN32 #define getchar getchar_unlocked #endif #define MP make_pair #define PB push_back #define ST first #define ND second typedef long long int LLI; typedef unsigned long long int LLU; typedef long double LD; typedef pair<int, int> pii; typedef pair<long long int, long long int> pll; typedef vector<int> vi; template<class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";} template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) { while(*sdbg!=',') cerr<<*sdbg++; cerr<<"="<<h<<","; _dbg(sdbg+1, a...); } #define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__) #define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) int kek[500007]; int32_t main() { int n; scanf("%d", &n); for(int i = 1; i <= n; ++i){ int x; scanf("%d", &x); ++kek[x]; } int odp = 0; for(int i = 0; i < 500006; ++i){ if(kek[i] > 0) odp = max(odp, i); kek[i + 1] += kek[i] / 2; } printf("%d", odp); } |
English