图片说明

代码:

#include<bits/stdc++.h>

using namespace std;

int main(){
    int n, k;
    cin >> n>>k;
    if (n < 6 && k == n / 2)
    {
        cout << -1;
        return 0;

    }
    if (k < n/2)
    {
        int i = 2;
        for (int j = 1; j <= k+1 &&i <= n;  j++, i+= 2)
        cout << i<<' ';
        i-=2;
        for (int j = i+1; j <= n; j++)
            cout << j<<' ';
        for (int j = 1; j <= i; j+=2)
            cout << j<<' ';
    }
    else {
        int i = 8;
        for (int j = 1; j <= k-2 &&i <= n;  j++, i+= 2)
            cout << i <<' ';
        cout << 2 <<' '<< 4 <<' '<< 6 <<' ';
        cout <<3 <<' '<<1 <<' ';
        for (int i = 5; i <= n; i+= 2)
            cout <<i <<' ';
    }
    return 0;
}