-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprop3.py
54 lines (48 loc) · 1.01 KB
/
prop3.py
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
def clist(n):
l = []
for i in range(1,n+1):
l.append(i)
return l
def costl(k, p):
if p < k-1:
return []
l = []
t = 0
c = 1
for i in range(k-1, 0, -1):
c += 1
if t+c+i-1 >= p:
r = p-t-i+1
l.append(r)
for k in range(i-1):
l.append(1)
t = p
break
t += c
l.append(c)
if t<p:
return []
return l
def operate(l, opeL):
length = len(opeL)
for i in range(length):
t = len(l)-(i+2)
sp = t+opeL[i]
l = l[:t]+ list(reversed(l[t:sp])) + l[sp:]
return l
def check_array():
inp = input().split()
n = int(inp[0])
p = int(inp[1])
l = clist(n)
opeL = costl(n,p)
l = operate(l, opeL)
result = " "
if opeL:
for item in l:
result += str(item)+ " "
else:
result =" IMPOSSIBLE"
print("Case #"+str(i+1)+": "+ str(result))
for i in range(int(input())):
check_array()