TCCC '23 Sept P2 - The Magical Classroom

View as PDF

Submit solution


Points: 3
Time limit: 2.0s
Memory limit: 256M

Author:
Problem type

Thornhill Computer Club 2023 - September Contest - Problem 2

In the futuristic school of Zornhill Secondary School (ZSS), a magical classroom exists with a special property. This magical classroom has the ability to change its length and width by casting spells in order to accommodate any class size. The classroom can be divided into a grid of 1 x 1 meter squares which can each fit a single desk for each student. However, to increase personal space between students, desks cannot be within grid space away from each other in all directions (including diagonals). Mr. Z, a teacher of ZSS, has decided to use the classroom for his upcoming course but does not know how big the classroom must be to fit his N students.

To solve this, he decides to cast S spells to increase or decrease the width or length of the classroom.

Given that the classroom starts with an initial width of W and initial length of L, can you determine whether the new classroom can fit all N students>?

Input Specifications

The first line of input will contain three integers, W and L, the width and length of the classroom (1 \le W, L \le 100) and N, the number of students in Mr. Z's class (1 \le N \le 1000).
The next line will contain a single integer S representing the number of spells Mr. Z cast (0 \le S \le 100).
The next S lines will contain two integers, C_w and C_l representing the change in width and the change in length of the S_th spell (-100 \le C_w, C_l \le 100).
Due to limitations with magic, if spells are casted to decrease the size of the classroom below 1 x 1, the classroom would continue to shrink until it reaches a size of 1 x 1.

Output Specifications

Output yes or no depending on whether or not the new class is large enough to fit Mr. Z's N students.

Sample Input 1

3 3 10
5
-2 1
6 -2
-3 5
5 -3
-1 1

Sample Output 1

yes

Explanation for Sample Output 1

After 5 spells, the final classroom size will be 8 x 5. In a class of this size, 10 desks for 10 students can fit inside this classroom in the following configuration.
Desks

Sample Input 2

10 8 1000
3
23 5
12 36
9 23

Sample Output 2

no

Explanation for Sample Output 2

The final room size would be 54 x 72 spaces. It is impossible to fit 1000 desks into a room of this size without having all desks at least one grid space away from each other.

Sample Input 3

10 10 5
8
95 34
12 1
-96 45
34 21
-23 -87
-64 -51
17 35
-15 -31

Sample Output 3

yes

Comments

There are no comments at the moment.