Help me in solving POSPREFS problem

My issue

My code

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,k;
        cin>>n>>k;
        for(int i=1;i<=k;i++)
        {
           cout<<i<<" "; 
        }
        for(int i=k+1;i<=n;i++)
        {
            cout<<-i<<" ";
        }
        cout<<endl;
    }

}

Problem Link: POSPREFS Problem - CodeChef

@tnaveen8
your logic is not right
like for n=5 and k=4
your output will be 1 2 3 4 -5
which is wrong since it will give 5 >0 i’s we need only 4
hint :- try to print consecutive with opposite signs