#include<iostream>
#include<assert.h>
#include<cstdio>
#include<string>
#include<cmath>
#include<bitset>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<utility>
using namespace std;
#define FOR(I,A,B) for(int I=(A);I<=(B);I++)
#define REP(I,N) for(int I=0;I<(N);I++)
#define ALL(X) (X).begin(),(X).end()
#define PB push_back
#define MP make_pair
#define f first
#define s second
//#define DEBUG true
#ifdef DEBUG
#define SHOW(NAME, VAL) cout << NAME << ": " << VAL << '\n'
#else
#define SHOW(NAME, VAL)
#endif
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef long long ll;
typedef vector<string> VS;
constexpr int maxDenom = 201718;
int coins[maxDenom + 2];
void test() {
// initialize
FOR(i, 0, maxDenom) {
coins[i] = 0;
}
// read input
int n;
cin >> n;
REP(i, n) {
int a;
cin >> a;
coins[a]++;
}
// propagate
FOR(i, 0, maxDenom) {
coins[i + 1] += coins[i] / 2;
coins[i] %= 2;
}
// find max
int highestDenom = 0;
FOR(i, 0, maxDenom + 1) {
if(coins[i] > 0) {
highestDenom = i;
}
}
int coinsCount = coins[highestDenom];
while(coinsCount >= 2) {
highestDenom++;
coinsCount /= 2;
}
cout << highestDenom << '\n';
}
int main() {
std::ios_base::sync_with_stdio(false);
int t;
t = 1;
// cin >> t;
FOR(i, 1, t) {
test();
}
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 | #include<iostream> #include<assert.h> #include<cstdio> #include<string> #include<cmath> #include<bitset> #include<vector> #include<map> #include<set> #include<algorithm> #include<utility> using namespace std; #define FOR(I,A,B) for(int I=(A);I<=(B);I++) #define REP(I,N) for(int I=0;I<(N);I++) #define ALL(X) (X).begin(),(X).end() #define PB push_back #define MP make_pair #define f first #define s second //#define DEBUG true #ifdef DEBUG #define SHOW(NAME, VAL) cout << NAME << ": " << VAL << '\n' #else #define SHOW(NAME, VAL) #endif typedef vector<int> VI; typedef pair<int,int> PII; typedef long long ll; typedef vector<string> VS; constexpr int maxDenom = 201718; int coins[maxDenom + 2]; void test() { // initialize FOR(i, 0, maxDenom) { coins[i] = 0; } // read input int n; cin >> n; REP(i, n) { int a; cin >> a; coins[a]++; } // propagate FOR(i, 0, maxDenom) { coins[i + 1] += coins[i] / 2; coins[i] %= 2; } // find max int highestDenom = 0; FOR(i, 0, maxDenom + 1) { if(coins[i] > 0) { highestDenom = i; } } int coinsCount = coins[highestDenom]; while(coinsCount >= 2) { highestDenom++; coinsCount /= 2; } cout << highestDenom << '\n'; } int main() { std::ios_base::sync_with_stdio(false); int t; t = 1; // cin >> t; FOR(i, 1, t) { test(); } return 0; } |
English