#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
vector<int> cnt;
while (n--) {
int a;
scanf("%d", &a);
if ((int)cnt.size() <= a) {
cnt.resize(a+1, 0);
}
cnt[a]++;
}
for (size_t i=0; i+1 < cnt.size(); i++) {
cnt[i+1] += cnt[i] / 2;
}
while (cnt.back() > 1) {
cnt.push_back(cnt.back() / 2);
}
printf("%d\n", (int)cnt.size() - 1);
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 | #include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); vector<int> cnt; while (n--) { int a; scanf("%d", &a); if ((int)cnt.size() <= a) { cnt.resize(a+1, 0); } cnt[a]++; } for (size_t i=0; i+1 < cnt.size(); i++) { cnt[i+1] += cnt[i] / 2; } while (cnt.back() > 1) { cnt.push_back(cnt.back() / 2); } printf("%d\n", (int)cnt.size() - 1); return 0; } |
English