-
Notifications
You must be signed in to change notification settings - Fork 0
/
1512E.py
50 lines (44 loc) · 1.04 KB
/
1512E.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
#######puzzleVerma#######
import sys
import math
mod = 10**9+7
LI=lambda:[int(k) for k in input().split()]
input = lambda: sys.stdin.readline().rstrip()
IN=lambda:int(input())
S=lambda:input()
r=range
for t in r(IN()):
n,l,r,s=LI()
num=r-l+1
baki=n-num
numsum=num*(num+1)//2
totalsum=n*(n+1)//2
bakisum=baki*(baki+1)//2
maxsum=totalsum-bakisum
if ((s<numsum) or (s>maxsum)):
print(-1)
continue
else:
permu=[int(i+1) for i in range(n)]
st=1
en=n
cursum=0
ans=[0 for i in range(n)]
l-=1
r-=1
for i in range(l,r+1):
ans[i]=st
st+=1
cursum+=ans[i]
if cursum<s:
for i in range(r,l-1,-1):
while ((ans[i]<en) and (cursum<s)):
ans[i]+=1
cursum+=1
en-=1
for i in range(l,r+1):
permu.remove(ans[i])
for i in range(n):
if ((i<l) or (i>r)):
ans[i]=permu.pop()
print(*ans)