// Skarbonka.cpp : Defines the entry point for the console application. // #include <cassert> #include <iostream> #include <istream> #include <fstream> #include <algorithm> #include <cstdio> #include <complex> #include <vector> #include <set> #include <map> #include <cmath> #include <queue> #include <string> #include <cstdlib> #include <memory> #include <ctime> #include <bitset> #include <queue> #include <stack> #include <unordered_map> #include <unordered_set> #include <bitset> using namespace std; #define SORT(v) sort((v).begin(),(v).end()) #define UN(v) SORT(v),(v).erase(unique((v).begin(),(v).end()),(v).end()) const int MOD = 1e9 + 7; const int SIZE = 1e6 + 10; const double EPS = 1e-12; const double PI = acos(-1); class Skarbonka { private: int n; int m = 0; static const int A = 1000002; static const int B = 300000; int a[A]; int b[B]; //should be enough string result; char curr = '0'; public: void Read() { cin >> n; std::fill_n(a, A-1, 0); std::fill_n(b, B, 0); for (int i = 0; i < n; i++) { cin >> a[i]; m = std::max(m, a[i]); b[a[i]] += 1; } } void Solve() { for (int i = 0; i <= m; i++) { if (b[i] > 1) { int next = b[i] / 2; b[i + 1] += next; m = std::max(m, i + 1); } } cout << m << endl; } }; int main()//int argc, _TCHAR* argv[]) { Skarbonka *p = new Skarbonka(); p->Read(); p->Solve(); delete p; 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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | // Skarbonka.cpp : Defines the entry point for the console application. // #include <cassert> #include <iostream> #include <istream> #include <fstream> #include <algorithm> #include <cstdio> #include <complex> #include <vector> #include <set> #include <map> #include <cmath> #include <queue> #include <string> #include <cstdlib> #include <memory> #include <ctime> #include <bitset> #include <queue> #include <stack> #include <unordered_map> #include <unordered_set> #include <bitset> using namespace std; #define SORT(v) sort((v).begin(),(v).end()) #define UN(v) SORT(v),(v).erase(unique((v).begin(),(v).end()),(v).end()) const int MOD = 1e9 + 7; const int SIZE = 1e6 + 10; const double EPS = 1e-12; const double PI = acos(-1); class Skarbonka { private: int n; int m = 0; static const int A = 1000002; static const int B = 300000; int a[A]; int b[B]; //should be enough string result; char curr = '0'; public: void Read() { cin >> n; std::fill_n(a, A-1, 0); std::fill_n(b, B, 0); for (int i = 0; i < n; i++) { cin >> a[i]; m = std::max(m, a[i]); b[a[i]] += 1; } } void Solve() { for (int i = 0; i <= m; i++) { if (b[i] > 1) { int next = b[i] / 2; b[i + 1] += next; m = std::max(m, i + 1); } } cout << m << endl; } }; int main()//int argc, _TCHAR* argv[]) { Skarbonka *p = new Skarbonka(); p->Read(); p->Solve(); delete p; return 0; } |