stage is a succession of n integers from 1 to n, in which every one of the numbers happen precisely once. For instance, [1], [3,5,2,1,4], [1,3,2] are stages, and [2,3,2], [4,3,1], [0] are not. Polycarp was given four integers n, l, r (1≤l≤r≤n) and s (1≤s≤n(n+1)2) and requested to find a stage p of numbers from 1 to n that fulfills the accompanying condition:
Correct answer will be upvoted else downvoted. Computer science.
stage is a succession of n integers from 1 to n, in which every one of the numbers happen precisely once. For instance, [1], [3,5,2,1,4], [1,3,2] are stages, and [2,3,2], [4,3,1], [0] are not.
Polycarp was given four integers n, l, r (1≤l≤r≤n) and s (1≤s≤n(n+1)2) and requested to find a stage p of numbers from 1 to n that fulfills the accompanying condition:
s=pl+pl+1+… +pr.
For instance, for n=5, l=3, r=5, and s=8, the accompanying stages are reasonable (not all choices are recorded):
p=[3,4,5,2,1];
p=[5,2,4,3,1];
p=[5,2,1,3,4].
However, for instance, there is no change reasonable for the condition above for n=4, l=1, r=1, and s=5.
Help Polycarp, for the given n, l, r, and s, find a stage of numbers from 1 to n that fits the condition above. In case there are a few appropriate changes, print any of them.
Input
The primary line contains a solitary integer t (1≤t≤500). Then, at that point, t experiments follow.
Each experiment comprise of one line with four integers n (1≤n≤500), l (1≤l≤n), r (l≤r≤n), s (1≤s≤n(n+1)2).
It is ensured that the amount of n for all input informational indexes doesn't surpass 500.
Output
For each experiment, output on a different line:
n integers — a stage of length n that fits the condition above if such a change exists;
- 1, in any case.
Step by step
Solved in 3 steps with 1 images