
The cost array is a permutation of the first M natural numbers.
The shop has unlimited supplies of candies.
In case of multiple permutations, print one which is lexicographically minimum.
Letβs say βNβ = 3 , βMβ = 5
The integers told by children are { {2 , 4 , 1} ,{1 , 3 , 2} , {3, 3 , 5} }
The optimal permutation will be {3 2 1 4 5}
Costs paid by Ninja are 7, 12, and 5, respectively.
The total cost would be 7 + 12 + 5 = 24
First-line contains 'T,' denoting the number of Test cases.
For each Test case:
The first contains two integers, 'N' and βMβ, where βNβ is the number of children and βMβ is the number of candies available in the shop.
Next, the βNβ line contains three integers, βLβ, βRβ, and βXβ.
For each test case, print βMβ integers, i.e., the permutation of βMβ natural numbers.
1<=βTβ<=10
1<=βNβ<=10^5
1<=βMβ<=10^5
1<=βLβ<=βRβ<=βMβ
1<=βXβ<=10^5
Time Limit: 1 sec
Calculate the frequency of each candy sold, and since we have to reduce our total cost, we can assign the lower price to the higher-selling candy. Hence, we will give the cost in decreasing order of their selling quantity. Assign cost 1 to most selling candy, cost 2 to the second most selling candy, etc.
Calculate the frequency of each candy sold, and since we have to reduce our total cost, we can assign the lower price to the higher-selling candy. Hence, we will give the cost in decreasing order of their selling quantity. To find out the number of candies sold, we could use the prefix sum. For all demands (L, R, X), add X to the Lth position and subtract X from the R+1th position of the count array.
Now take the prefix sum of the count array.