fork download
  1.  
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. # include <stdio.h>
  5. # include <math.h>
  6.  
  7. int main()
  8. {
  9.  
  10. int ans=0;
  11. int n;
  12. scanf("%d",&n);
  13. int temp;
  14. map<int,int>arr;
  15. for(int i=0;i<n;i++)
  16. {scanf("%d",&temp);
  17. arr[temp]++;
  18. }
  19. map<int,int>::iterator it=arr.begin();
  20. while(it!=arr.end())
  21. { // it=arr.begin();
  22. int val=it->second;
  23. int key=it->first;
  24. if(val%2==0)
  25. { int k=val/2;
  26. it->second=it->second-val;
  27. arr[1+key]+=k;
  28.  
  29. }
  30. else { it->second=it->second-1;
  31. ans=ans+1; }
  32.  
  33.  
  34. if(it->second<=0)
  35. it++;
  36. }
  37. cout<<ans<<endl;
  38. }
Time limit exceeded #stdin #stdout 5s 3460KB
stdin
Standard input is empty
stdout
Standard output is empty