-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDSA01002.cpp
More file actions
66 lines (62 loc) · 956 Bytes
/
DSA01002.cpp
File metadata and controls
66 lines (62 loc) · 956 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include<bits/stdc++.h>
using namespace std;
bool check(int a[], int n)
{
int l = 1;
int k = n;
while(l<=k)
{
if(a[l] != a[k]) return 0;
l++;
k--;
}
return 1;
}
int main()
{
int t;
cin >> t;
while(t--)
{
int n, k;
cin >> n >> k;
int a[k+5] = {};
for(int i = 1; i<=k; i++)
{
cin >> a[i];
}
int check = 1;
for(int i = 1; i<=k;i++)
{
if(a[i] != n-k+i)
{
check = 0;
}
}
if(check)
{
for(int i = 1; i<=k; i++)
{
cout << i << ' ';
}
}
else
{
int l = k;
while(a[l] == n-k+l && l)
{
l--;
}
a[l]++;
for(int i = l+1; i<=k; i++)
{
a[i] = a[i-1] + 1;
}
for(int i = 1; i<=k; i++)
{
cout << a[i] << ' ';
}
}
cout << endl;
}
}