Click here to Skip to main content
16,022,417 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
There are N people numbered from 1 to N, standing in a queue to withdraw money from an ATM. The queue is formed in ascending order of their number. The person numbered i wants to withdraw amount Ai. The maximum amount a person can withdraw at a time is X. If they need more money than X, they need to go stand at the end of the queue and wait for their turn in line. A person leaves the queue once they have withdrawn the required amount.

You need to find the order in which all the people leave the queue.
Input
The first line of the input gives the number of test cases T. T test cases follow.

The first line of each test case gives two space separated integers: the number of people standing in the queue, N and the maximum amount X that can be withdrawn in one turn.
The next line contains N space separated integers Ai.
Output
For each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y is the space separated list of integers that denote the order in which the people leave the queue.

Limits
Time limit: 20 seconds per test set.
Memory limit: 1GB.
1 ≤ T ≤ 100.

Test Set 1
1 ≤ N ≤ 100.
1 ≤ Ai ≤ 100.
1 ≤ X ≤ 100.

Test Set 2
1 ≤ N ≤ 105 for at most 10 test cases. For the remaining cases, 1 ≤ N ≤ 100
1 ≤ Ai ≤ 109.
1 ≤ X ≤ 109.

Sample

Input

Output

2
3 3
2 7 4
5 6
9 10 4 7 2


Case #1: 1 3 2
Case #2: 3 5 1 2 4

What I have tried:

I am trying to get its solution but help me.
Posted
Updated 26-Sep-20 22:16pm

Quote:
I am trying to get its solution but help me.

If you have a specific problem or question, you need to state it. Otherwise, you are asking us to solve the problem, and this will not happen soon.

This problem is typical from challenges sites, you need to understand that you will never learn programming by solving such problems, they are there to allow you to test your skills. If you fail to solve the problem, it just mean your skills are not advanced enough.

Advice:
- Learn properly Java or other languages
- Learn one or more analyze methods, E.W. Djikstra/N. Wirth Stepwize Refinement/top-Down method is a good start.
Structured Programming.pdf[^]
https://en.wikipedia.org/wiki/Top-down_and_bottom-up_design[^]
https://en.wikipedia.org/wiki/Structured_programming[^]
https://en.wikipedia.org/wiki/Edsger_W._Dijkstra[^]
https://www.cs.utexas.edu/users/EWD/ewd03xx/EWD316.PDF[^]
Program Development by Stepwise Refinement[^]
- Learn Algorithms and Data-Structures.
GitHub - The-Art-of-Computer-Programming-Books: "Everyday life is like programming, I guess. If you love something you can put beauty into it." ? Donald E. Knuth[^]
 
Share this answer
 
We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.
 
Share this answer
 
If you want to learn Java then your time would be better spent working through The Java™ Tutorials[^], where you will learn from actual programming samples. Obscure mathematical problems are of very limited use and rarely encountered in the real world.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900