Problem:
Score : 800 points

Problem Statement

In Finite Encyclopedia of Integer Sequences (FEIS), all integer sequences of lengths between 1 and N (inclusive) consisting of integers between 1 and K (inclusive) are listed.

Let the total number of sequences listed in FEIS be X. Among those sequences, find the (X/2)-th (rounded up to the nearest integer) lexicographically smallest one.

Constraints

1 \leq N,K \leq 3 × 10^5

N and K are integers.

Input

Input is given from Standard Input in the following format:

K N

Output

Print the (X/2)-th (rounded up to the nearest integer) lexicographically smallest sequence listed in FEIS, with spaces in between, where X is the total number of sequences listed in FEIS.

Sample Input 1

3 2

Sample Output 1

2 1

There are 12 sequences listed in FEIS: (1),(1,1),(1,2),(1,3),(2),(2,1),(2,2),(2,3),(3),(3,1),(3,2),(3,3).
The (12/2 = 6)-th lexicographically smallest one among them is (2,1).

Sample Input 2

2 4

Sample Output 2

1 2 2 2

Sample Input 3

5 14

Sample Output 3

3 3 3 3 3 3 3 3 3 3 3 3 2 2

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
void normalize(vector<P> &v)
{
    if(v.size() < 2) return;
    if(v.back().first == v[v.size()-2].first)
    {
        v[v.size()-2].second += v.back().second;
        v.pop_back();
    }
}

int main()
{
    int k, n;
    cin >> k >> n;

    if(k % 2 == 0)
    {
        cout << k/2 << " ";
        for(int i = 0; i < n-1; i++)
        {
            cout << k << " ";
        }
        cout << endl;
        return 0;
    }

    vector<P> v;
    v.push_back(P((k+1)/2, n));
    int count = n;
    for(int i = 0; i < n/2; i++)
    {
        int cand = v.back().first;
        if(cand != 1)
        {
            if(v.back().second == 1)
            {
                v.back().first--;
            }
            else
            {
                v.back().second--;
                v.push_back(P(cand-1, 1));
                normalize(v);
                if(n - count > 0)
                {
                    v.push_back(P(k, n-count));
                    count = n;
                }
            }
        }
        else
        {
            if(v.back().second == 1)
            {
              v.pop_back();
              count--;
            }
            else
            {              
              v.back().second--;
              count--;
            }
        }
    }
    for(int i = 0; i < v.size(); i++)
    {
        for(int j = 0; j < v[i].second; j++)
        {
            cout << v[i].first << " ";
        }
    }
}