#include <iostream>
using namespace std;
const int N = 1e6 + 5;
int cnt[N];
int main(){
int n;
cin >> n;
int maxw = -1;
for(int i = 0; i < n; i++){
int w;
cin >> w;
cnt[w]++;
maxw = max(maxw, w);
}
int res = 0;
for(int i = 0; i <= maxw || cnt[i]; i++){
if(cnt[i] == 0){
continue;
}
cnt[i + 1] += cnt[i] / 2;
cnt[i] %= 2;
if(cnt[i] > 0){
res++;
}
}
cout << res << endl;
return 0;
}
按照题解的方法写的,但是无缘无故tle了。