#include <iostream> #include <iomanip> #include <algorithm> #include <cmath> #include <climits> #include <vector> #include <map> #include <queue> #include <string> #include <cstdio> #define MOD 1000000007 #define ll long long #define ld long double #define pi pair <int, int> #define pll pair <long long, long long> #define fi first #define se second #define mp make_pair #define pb push_back using namespace std; int ile[300007]; int n, a, maks, d; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for(int i=0; i<n; i++) { cin >> a; ile[a]++; } maks=0; for(int i=0; i<300000; i++) { if(ile[i]>0) { maks=i; } d=ile[i]/2; ile[i+1]+=d; } cout << maks << "\n"; }
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 | #include <iostream> #include <iomanip> #include <algorithm> #include <cmath> #include <climits> #include <vector> #include <map> #include <queue> #include <string> #include <cstdio> #define MOD 1000000007 #define ll long long #define ld long double #define pi pair <int, int> #define pll pair <long long, long long> #define fi first #define se second #define mp make_pair #define pb push_back using namespace std; int ile[300007]; int n, a, maks, d; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for(int i=0; i<n; i++) { cin >> a; ile[a]++; } maks=0; for(int i=0; i<300000; i++) { if(ile[i]>0) { maks=i; } d=ile[i]/2; ile[i+1]+=d; } cout << maks << "\n"; } |