Editorial for TCCC '23 Sept P2 - The Magical Classroom


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.

Submitting an official solution before solving the problem yourself is a bannable offence.

Authors: KurbyDoo

Let W and L represent the width and length of the classroom.

To solve the problem, simply process each spell and keep track of the current width and length of the room by adding to the width and length.
Since the first index corresponds to the change in width, simply add this value to the current width. The same can be done for the length of the classroom, corresponding to the second index within the input.

Notice, the width or height classroom cannot be reduced to a size lower than 1 x 1. To account for this, simply set W = MAX(1, W) and H = MAX(1, H) after processing each spell, where MAX() represents a function that returns the largest value given two inputs. This prevents the width or length of the class from every falling below 1.

The last step is to simply calculate the maximum number of desks within the final classroom and compare it with the number of desks required. This can be calculated with the formula \lfloor\frac{W + 1}{2}\rfloor \times \lfloor\frac{L + 1}{2}\rfloor, where \lfloor X \rfloor represents the largest integer equal to or smaller than X.


Comments

There are no comments at the moment.