-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAbsolutePermutation.cpp
More file actions
60 lines (45 loc) · 1 KB
/
AbsolutePermutation.cpp
File metadata and controls
60 lines (45 loc) · 1 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// problem: "https://www.hackerrank.com/challenges/absolute-permutation/problem"
#include<iostream>
using namespace std;
int main()
{
long int T,N,K,i,j,x,y;
cin>>T;
for(i=0;i<T;i++)
{
cin>>N>>K;
if(K==0)
{
for(j=1;j<N+1;j++)
cout<<j<<" ";
cout<<endl;
continue;
}
if(N%(2*K)!=0)
{
cout<<-1<<endl;
continue;
}
else
{
x=1;
for(j=1;j<N+1;j++)
{
if(x<=K)
{
cout<<j+K<<" ";
x++;
}
else
{
cout<<j-K<<" ";
x++;
if(x>(2*K))
x=1;
}
}
}
cout<<endl;
}
return 0;
}