#include <iostream> #include<sstream> #include<fstream> #include<algorithm> #include <vector> #include <stdexcept> #define ll long long using namespace std; int A[300000]; int main() { std::ios::sync_with_stdio(false); istream& my_in = cin; int n; cin >>n; for(int i=0;i<n;i++){ int x; cin >> x; A[x]++; } int res =0; for(int i=0;i<300000;i++) { A[i+1]+=A[i]/2; if(A[i]>0)res = i; } 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 | #include <iostream> #include<sstream> #include<fstream> #include<algorithm> #include <vector> #include <stdexcept> #define ll long long using namespace std; int A[300000]; int main() { std::ios::sync_with_stdio(false); istream& my_in = cin; int n; cin >>n; for(int i=0;i<n;i++){ int x; cin >> x; A[x]++; } int res =0; for(int i=0;i<300000;i++) { A[i+1]+=A[i]/2; if(A[i]>0)res = i; } cout << res<<endl; return 0; } |