Submit | All submissions | Best solutions | Back to list |
ACMCEG2C - Pick the candies |
Pick the Candies
Many children went to a sweet shop. There were n candy varieties and each variety is kept in a separate bowl. The sweetness of each variety is written on the bowl. All the children wanted the candy with highest sweetness value. As there are only limited candies in each variety, the shop keeper makes a rule. According to the rule, the shopkeeper will show selectively chosen k varieties to every children. The children can pick any one of those varieties and move away. To make it easy for him, the shop keeper shows the
varieties 1,2,...,k to children1,
varieties 2,3,…,k+1 to children2,
varieties 3,4,…,k+2 to children3 and so on..
All the children are good at math. Find what variety each child will choose.
Input Specification:
The first line contains an integer t, the number of test cases. For each test case the input consists of two lines. The first line contains two integers n(number of candy varieties) and k. The next line contains n number of integers, the sweetness values of all the candy varieties.
Output Specification:
For each test case, print the candy varieties chosen by the children.
Input Constraints:
1<=t<=1000
1<=n<=10000
1<=k<=n
0<=Sweetness value<=10000
Sample Input:
3
5 3
1 2 3 4 5
4 2
7 1 6 8
9 5
7 14 3 0 2 2 2 2 2
Sample Output:
3 4 5
7 6 8
14 14 3 2 2
Hint: use deque
Added by: | cegprakash |
Date: | 2012-03-30 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: BF GOSU |
hide comments
|
|||||
2021-01-12 18:50:48
Ac in one go . Using both first using dequeue and second multiset |
|||||
2020-08-05 15:21:43
Segment Tree Ac in one go :) |
|||||
2019-08-12 13:47:03
should i use deque?? reply : YES Last edit: 2019-09-30 14:41:01 |
|||||
2019-04-09 20:54:22
Use Deque to keep track of elements of the variety of candies. If i is greater [spoiler] pop the [spoiler] Based of condition only keep [spoiler] Last edit: 2019-05-02 09:39:51 |
|||||
2018-05-19 20:36:32
i came to this method and got ac |
|||||
2018-05-19 12:49:13
can anyone explain the [spoiler] technique for this problem Last edit: 2019-01-05 13:13:36 |
|||||
2018-04-22 22:30:58
got AC, using concept : [spoiler] Last edit: 2019-01-05 13:13:44 |
|||||
2017-08-19 12:10:47
AC in one go!!! |
|||||
2017-07-17 10:05:36
O(spoiler) solution in 1 go. Last edit: 2017-08-02 12:45:40 |
|||||
2017-06-11 22:05:16
What about 3rd test case, I don't understand |