-
Notifications
You must be signed in to change notification settings - Fork 6
/
FNFP(Codechef).cpp
35 lines (31 loc) · 929 Bytes
/
FNFP(Codechef).cpp
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
/*
Fixed number of Fixed Points
Given a positive integer n and an integer k such that 0≤k≤n, find any permutation A of 1,2…n such that the number of indices for which Ai=i is exactly k.
If there exists no such permutation, print −1. If there exist multiple such permutations, print any one of them.
*/
#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
cin >> t;
while(t--){
int n , k;
cin >> n >> k;
if(n - 1 == k) cout << -1 << "\n";
else if(n == k){
for(int i = 1 ; i <= k ; i++){
cout << i << " ";
}
cout << "\n";
}
else{
int diff = n - k;
for(int i = 2 ; i <= diff ; i++){
cout << i << " ";
}
cout << 1 << " ";
for(int i = diff + 1 ; i <= n ; i++) cout << i << " ";
cout << "\n";
}
}
}