In A Botanical Garden

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

In a botanical garden, people can book tickets online as well as at the ticket

counter directly. Each ticket has a ticket number and a slot number. The
security in-charge allows people to enter the garden only according to the
timeslot and ticket number. The people who have time slot 1 can enter the
garden before anyone with time slot 2. If more than one person from the
same time slot comes, they will be allowed according to their ticket
numbers.
If N people arrive at a time, find the order in which the security in-charge
allows them to enter the garden.

Write a program to print the ticket numbers of N people in the order in


which they will be allowed to enter the garden. 
 
You must read the input from STDIN (standard input) and write the output
to STDOUT (standard output). Do not print arbitrary strings while reading
the input or printing the output as those would contribute to STDOUT.
 
Constraints:
I) 1 < N < 1000
II) The ticket numbers of people in any slot are unique.
Input Format:
The first line of input contains the number of tickets, N.
The next N lines contain two integers separated by single white space,
where the first integer is the ticket number and the second integer is the
time slot.
 
Output Format:
The output contains N integers separated by a single white space, which
are ticket numbers of the people in the order in which they are allowed to
enter the garden. 
 
Sample Input 1:
7
23
41
64
52
13
73
32
 
Sample Output 1:
4 3 5 1 2 7 6 
Explanation 1:
N = 7.
There is only one person from time slot 1 and he gets to enter first. His
ticket number is 4, which is printed first.
There are two people from time slot 2:  3 and 5. Printing according to ticket
numbers gives 3 and 5 as the next entries in the output.
There are three people from time slot 3: 2 1 and 7. Printing according to
ticket numbers gives 1, 2, and 7 as the next entries in the output.
There is only one person from time slot 4: 6 and he is the last person
allowed to enter the garden.
So, the order in which ticket numbers are printed is 4 3 5 1 2 7 6.

Sample Input 2:
5
65
82
15
64
61

Sample Output 2:
68616

Explanation 2:
N = 5.
There is only one person from time slot 1 and he gets to enter first. His
ticket number is 6, which is printed first.
There is only one person from time slot 2 and he gets to enter as the
second person. His ticket number is 8, which is printed next.
There is no one from time slot 3.
There is only one person from time slot 4 and he gets to enter as the
third person. His ticket number is 6, which is printed next.
There are two people from time slot 5:  6 and 1. Printing according to ticket
numbers gives 1 and 6 as the next entries in the output.
Printing all these ticket numbers gives 6 8 6 1 6 as the output.

You might also like