Puzzle - There are n animals in the queue to Dr. Dolittle. [Queue Problem]

There are n animals in the queue to Dr. Dolittle. When an animal comes into the office, the doctor examines him, gives prescriptions, appoints tests and may appoint extra examination. Doc knows all the forest animals perfectly well and therefore knows exactly that the animal number i in the queue will have to visit his office exactly ai times. We will assume that an examination takes much more time than making tests and other extra procedures, and therefore we will assume that once an animal leaves the room, it immediately gets to the end of the queue to the doctor. Of course, if the animal has visited the doctor as many times as necessary, then it doesn't have to stand at the end of the queue and it immediately goes home.

Doctor plans to go home after receiving k animals, and therefore what the queue will look like at that moment is important for him. Since the doctor works long hours and she can't get distracted like that after all, she asked you to figure it out.

Input

The first line of input data contains two space-separated integers n and k (1≤n≤105, 0≤k≤1014). In the second line are given space-separated integers a1,a2,...,an (1≤ai≤109).

Output

If the doctor will overall carry out less than k examinations, print a single number "-1" (without quotes). Otherwise, print the sequence of numbers — number of animals in the order in which they stand in the queue.

How to solve this?!? Brute force will not work, as the inputs are very big... 😔

Replies

  • vik001ind
    vik001ind
    For given inputs, a program can be written. It's not as hard as it looks.
  • PraveenKumar Purushothaman
    PraveenKumar Purushothaman
    Can ya share the logic... I can't even understand the description here... 😔
  • vik001ind
    vik001ind
    We will first store the values of a in an queue (linked list). We will iterate this list & decrement the element after each examination. As a becomes zero, we will delete that element from list. We can have a counter to record the no. of animals checked after certain time.
    To counter with examination & tests we can use a sleep function, after certain amount of time, doc can check the how many animals he has checked so far(k).
    The question doesn't clearly says, what is asked ..
    Doctor plans to go home after receiving k animals, and therefore what the queue will look like at that moment is important for him. Since the doctor works long hours and she can't get distracted like that after all, she asked you to figure it out.
  • PraveenKumar Purushothaman
    PraveenKumar Purushothaman
    Thanks... Lemme try and say whats happening... 😀
  • PraveenKumar Purushothaman
    PraveenKumar Purushothaman
    This is what exactly brute force solution to this problem... But the value of k ranges between 1 and 10 ^ 14 and the constraint is that the program should generate output within 2 seconds...... 😔 So this approach ll fail...

You are reading an archived discussion.

Related Posts

to all ceans, though we are electrical engineer and this subject seem to be related to mechanical ones but we are also going to place in power plants(NTPC,BHEL,etc) so we...
i noe this question is often repeated...but i want a fresh review on this...as i m placed in both..i am very much confused about which to join..its been said that...
multicasting in java, which contains a single administrator and and a single leader for each sub group
Hi sir, i have passed my SSC examination this year and i want to do diploma in chemical engineering.So what can i do for it? and will you elaberate scope...
I'm a student at NMIMS University Mumbai, pursuing MBATECH(IT), in the Fourth Year Click Here I want to make a career as a business analyst in the tablet & smartphone...