#include <bits/stdc++.h> using namespace std; template <typename T> T load() { T r; cin >> r; return r; } const int limitInputExponent = 201718; //const int limitInputN = 1000000; const int limitMyArraySize = limitInputExponent + 300; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); auto n = load<int>(); auto haveNominal = vector<bool>(limitMyArraySize, false); for (int i=0; i<n; ++i) { auto val = load<int>(); while (haveNominal[val]) haveNominal[val] = false, ++val; haveNominal[val] = true; } for (int i=limitMyArraySize-1; i>=0; --i) if (haveNominal[i]) return cout << i << '\n', 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 | #include <bits/stdc++.h> using namespace std; template <typename T> T load() { T r; cin >> r; return r; } const int limitInputExponent = 201718; //const int limitInputN = 1000000; const int limitMyArraySize = limitInputExponent + 300; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); auto n = load<int>(); auto haveNominal = vector<bool>(limitMyArraySize, false); for (int i=0; i<n; ++i) { auto val = load<int>(); while (haveNominal[val]) haveNominal[val] = false, ++val; haveNominal[val] = true; } for (int i=limitMyArraySize-1; i>=0; --i) if (haveNominal[i]) return cout << i << '\n', 0; } |