You have been asked to find the largest affordable location for constructing a new pyramid. In order to help you decide, you have been provided with a survey of the available land which has been conveniently divided into an
The survey has identified a set of
Task
Write a program that, given the dimensions
Constraints
Input Specification
Your program must read from the standard input the following data:
- Line
contains two integers separated by a single space that represent and respectively. - Line
contains the integer , the maximum cost you can afford (i.e., your budget). - Line
contains the integer , the number of obstacles found in the survey. - Each of the next
lines describes an obstacle. The of these lines describes the obstacle. Each line consists of integers: , , , , and separated by single spaces. They represent respectively the coordinates of the bottommost leftmost cell of the obstacle, the coordinates of the topmost rightmost cell of the obstacle, and the cost of removing the obstacle. The bottommost leftmost cell on the grid has coordinates and the topmost rightmost cell has coordinates .
Output Specification
Your program must write to the standard output a single line containing one integer, the maximum possible side length of the base of the pyramid that can be prepared. If it is not possible to build any pyramid, your program should output the number
Subtasks
- (
points) , - (
points) , - (
points) ,
Sample Input 1
6 9
42
5
4 1 6 3 12
3 6 5 6 9
1 3 3 8 24
3 8 6 9 21
5 1 6 2 20
Sample Output 1
4
Explanation for Sample Output 1
The figure shows two possible locations for the pyramid's base, both having a side of length
Sample Input 2
13 5
0
8
8 4 10 4 1
4 3 4 4 1
10 2 12 2 2
8 2 8 4 3
2 4 6 4 5
10 3 10 4 8
12 3 12 4 13
2 2 4 2 21
Sample Output 2
3
Explanation for Sample Output 2
The figure shows the only possible location for the pyramid's base having a side of length
Comments