forked from umarsalman/Hackerrank-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathabsolute-permutation.cpp
More file actions
45 lines (42 loc) · 872 Bytes
/
Copy pathabsolute-permutation.cpp
File metadata and controls
45 lines (42 loc) · 872 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
int t;
cin>>t;
ll n,k,i,j,p,l;
for(int i=1;i<=t;i++)
{
cin>>n>>k;
// ll arr[n+1];
if(k==0)
{
for(j=1;j<=n;j++)
cout<<j<<" ";
}
else if(n%(2*k)!=0)
{
cout<<"-1";
}
else{
for(j=1;j<=n;j=j+2*k)
{
p=j+k;
for(l=0;l<k;l++)
{
cout<<p<<" ";
p++;
}
p=j;
for(l=0;l<k;l++)
{
cout<<p<<" ";
p++;
}
}
}
cout<<'\n';
}
return 0;
}