Language: C++


using namespace std;

typedef long long ll;

int main(){
 int N; cin>> N;
  
  vector<ll> A(N);
  
  for(int i = 0; i < N; i++){ cin >> A[i];}
  
  sort(A.begin(),A.end());
  
  vector<ll> kind; vector<ll> cnt;
  
  int head = 0; int tail = 0; 
  
  while( head < N && tail < N){ 
    
    while( A[head] == A[tail]){ tail++;}
    
    kind.push_back(A[head]);
    cnt.push_back(tail-head);
    
    head = tail;
    
  }
  
  vector<ll> ans;
  
  ll now = 1; //現在の数字
  ll sum = 0; //これまでの和
  int itr = 0; //kindのどこまで見たか
  const int m = (int)kind.size();
  
  while( itr < m){ 
    
    while( sum < kind[itr]-1){ sum++; ans.push_back(now);}
    // sum == kind[itr]-1まで足し続ける.
    
    while( sum+now == kind[itr] && itr < m ){ now++; itr++;}
    
    ans.push_back(now); sum += now;
    
    now = 1;
  }
  
  for(auto ne : ans){ cout << ne << " " ;}
 
  cout<< endl;
  
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:7:9: error: 'cin' was not declared in this scope
    7 |  int N; cin>> N;
      |         ^~~
a.cc:1:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
  +++ |+#include <iostream>
    1 | 
a.cc:9:3: error: 'vector' was not declared in this scope
    9 |   vector<ll> A(N);
      |   ^~~~~~
a.cc:1:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
  +++ |+#include <vector>
    1 | 
a.cc:9:12: error: expected primary-expression before '>' token
    9 |   vector<ll> A(N);
      |            ^
a.cc:9:14: error: 'A' was not declared in this scope
    9 |   vector<ll> A(N);
      |              ^
a.cc:13:3: error: 'sort' was not declared in this scope; did you mean 'short'?
   13 |   sort(A.begin(),A.end());
      |   ^~~~
      |   short
a.cc:15:12: error: expected primary-expression before '>' token
   15 |   vector<ll> kind; vector<ll> cnt;
      |            ^
a.cc:15:14: error: 'kind' was not declared in this scope
   15 |   vector<ll> kind; vector<ll> cnt;
      |              ^~~~
a.cc:15:29: error: expected primary-expression before '>' token
   15 |   vector<ll> kind; vector<ll> cnt;
      |                             ^
a.cc:15:31: error: 'cnt' was not declared in this scope; did you mean 'int'?
   15 |   vector<ll> kind; vector<ll> cnt;
      |                               ^~~
      |                               int
a.cc:30:12: error: expected primary-expression before '>' token
   30 |   vector<ll> ans;
      |            ^
a.cc:30:14: error: 'ans' was not declared in this scope
   30 |   vector<ll> ans;
      |              ^~~
a.cc:49:23: error: 'cout' was not declared in this scope
   49 |   for(auto ne : ans){ cout << ne << " " ;}
      |                       ^~~~
a.cc:49:23: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:51:3: error: 'cout' was not declared in this scope
   51 |   cout<< endl;
      |   ^~~~
a.cc:51:3: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:51:10: error: 'endl' was not declared in this scope
   51 |   cout<< endl;
      |          ^~~~
a.cc:1:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
  +++ |+#include <ostream>
    1 |