Book Covers
InterviewTime limit0.5sMemory limit1024 MB
Given a textbook and two covers, each described by two sides in centimeters and millimeters, pick the fitting cover with the smallest width, or report none.
- Level
Easy3 of 10
- Topics
- Implementation, Math, Sorting
- Solved
- No attempts yet
Problem
Chris is about to start first grade and is very excited. Eagerly preparing for the first day of school, he decides to pick the most suitable cover for his math textbook himself. Chris sees that his mother bought two covers of different sizes, but he cannot tell on his own whether either of them fits his math textbook. If both fit, he does not know which one is more suitable.
Help him by writing a program bindings that, given the dimensions of the textbook and the dimensions of the two available covers, picks the more suitable one according to these rules:
- a cover fits if there is at least 5 mm of clearance on each side of the textbook's width up to the cover's width, and the textbook's height is not greater than the cover's height;
- if both covers fit, the one with the smaller width is chosen.
The textbook and the covers are rectangles. By the width of a rectangle Chris means the shorter of its two sides.
Input
The first line of the standard input contains four integers: the dimensions of the math textbook. The first two are the centimeters and millimeters of one of its sides, and the next two are the centimeters and millimeters of the other side. The next two lines each contain four integers: the dimensions of one cover in centimeters and millimeters. The two covers have different dimensions.
Output
On the first line of the standard output, print either 1 or 2, indicating which cover, in order of input, is the most suitable. If no cover fits, print 0. If a cover fits, print on the second line of the standard output its width and height in centimeters, separated by a single space.
Constraints
- 0 < height and width ≤ 10 000
Hint
Explanation of example 2:
- The textbook dimensions are: width 311 mm and height 351 mm.
- The dimensions of cover 1 are: width 317 mm and height 375 mm.
- The dimensions of cover 2 are: width 190 mm and height 380 mm.
The cover must have a width of at least 321 mm, so neither cover satisfies the requirements and the program must print 0.