Questions Class 5
Questions Class 5
but narrow room that only one haybale can fit with respect to the width and
the length. So the haybales can only be stored by stacking them starting
from the floor. Initially the storage is empty and there are
FJ has a robot equipped with one arm that can hold one haybale.
With ADD command, the robot takes the next haybale in the warehouse and
command it takes the haybale on the top in the storage and carries it
to the barn. At the end of the week, FJ wants to learn the status of
Your program will help FJ to find out the list of the haybales.
For example, given the sequence of FJ's commands throughout the week,
Command Storage
======= =======
ADD 1
ADD 12
ADD 123
ADD 1234
REMOVE 123
ADD 1235
ADD 12356
REMOVE 1235
REMOVE 123
REMOVE 12
ADD 127
ADD 1278
REMOVE 127
REMOVE 12
REMOVE 1
REMOVE
ADD 9
ADD 9 10
REMOVE 9
ADD 9 11
INPUT FORMAT:
SAMPLE INPUT:
20
ADD
ADD
ADD
ADD
REMOVE
ADD
ADD
REMOVE
REMOVE
REMOVE
ADD
ADD
REMOVE
REMOVE
REMOVE
REMOVE
ADD
ADD
REMOVE
ADD
OUTPUT FORMAT:
SAMPLE OUTPUT:
11
Question 2:
in front of the line goes to the register and pays. Bessie would
can pay then buy something again. In that case, the customer
has to enter the line at the end again. The number of registers
C1 1
C5 15
C3 153
R3 53 1
C2 532 1
R3 32 15
C5 325 15
R2 25 3 15
C4 254 3 15
C1 2541 3 15
R3 541 3 152
C3 5413 3 152
R2 413 35 152
R1 13 4 35 152
C5 135 4 35 152
C2 1352 4 35 152
R1 2 45 3513 152
Here 'C' corresponds to the customer and 'R' corresponds to the register.
Then the list of the customers payed at the registers are as follows:
Register 1: 4 5 2
Register 2: 3 5 1 3
Register 3: 1 5 2
INPUT FORMAT:
SAMPLE INPUT:
C1
C5
C3
R3
C2
R3
C5
R2
C4
C1
R3
C3
R2
R1
C5
C2
R2
R2
R1
R1
OUTPUT FORMAT:
* Line 1..N: Line i has R_i, the number of customers in that register,
then R_i numbers corresponding to the list of the customers payed at register i
SAMPLE OUTPUT:
3452
43513
3152
Question 3:
1..N, are once again standing in a row. Cow i has height H_i (1 <=
H_i <= 1,000,000).
Each cow is looking to her left toward those with higher index
numbers. We say that cow i 'looks up' to cow j if i < j and H_i <
H_j. For each cow i, FJ would like to know the index of the first
Note: about 50% of the test data will have N <= 1,000.
INPUT FORMAT:
SAMPLE INPUT:
INPUT DETAILS:
OUTPUT FORMAT:
* Lines 1..N: Line i contains a single integer representing the
SAMPLE OUTPUT:
OUTPUT DETAILS:
Cows 1 and 2 both look up to cow 3; cows 4 and 5 both look up to cow 6; and
Question 4:
Farmer John has devised a brilliant method to paint the long fence next to
attaches a paint brush to his favorite cow Bessie, and then retires to
drink a cold glass of water as Bessie walks back and forth across the
fence, applying paint to any segment of the fence that she walks past.
moves (1 <= N <= 100,000). Example moves might be "10 L", meaning
Bessie moves 10 units to the left, or "15 R", meaning Bessie moves 15
like to know what area of the fence gets painted with at least K coats
of paint. Bessie will move at most 1,000,000,000 units away from the
INPUT FORMAT:
* Lines 2..1+N: Each line describes one of Bessie's N moves (e.g., "15
L").
62
2R
6L
1R
8L
1R
2R
INPUT DETAILS:
Bessie starts at position 0 and moves 2 units to the right, then 6 to the
left, 1 to the right, 8 to the left, and finally 3 to the right. FJ wants
OUTPUT DETAILS: