// Skarbonka [B].cpp : Defines the entry point for the console application.
//
#include <iostream>
#include <algorithm>
using namespace std;
const int MAXA = 202000;
int kub[MAXA];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
int maxel = 0;
int x;
for (int i = 0; i < n; i++) {
cin >> x;
kub[x]++;
maxel = max(x, maxel);
}
for (int i = 0; i <= maxel; i++) {
kub[i + 1] += (kub[i] / 2);
}
maxel++;
while (kub[maxel] > 0) {
kub[maxel + 1] += (kub[maxel] / 2);
maxel++;
}
cout << maxel - 1 << 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 31 32 | // Skarbonka [B].cpp : Defines the entry point for the console application. // #include <iostream> #include <algorithm> using namespace std; const int MAXA = 202000; int kub[MAXA]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; int maxel = 0; int x; for (int i = 0; i < n; i++) { cin >> x; kub[x]++; maxel = max(x, maxel); } for (int i = 0; i <= maxel; i++) { kub[i + 1] += (kub[i] / 2); } maxel++; while (kub[maxel] > 0) { kub[maxel + 1] += (kub[maxel] / 2); maxel++; } cout << maxel - 1 << endl; return 0; } |
English