Cut frame
Hard
Execution time limit is 1 second
Runtime memory usage limit is 64 megabytes
Rectangular frame was divided into N pieces. Each piece can be either a line segment, or "corner" - two segments, joined at right angles.
According to the lengths required to restore the original frame, or determine that it is impossible. The pieces can be rotated, but can not reflect. You have to use all the pieces.
Input
The input file contains the number of pieces N, followed by Npairs of integers a_i b_i, describing the length of two segments of "corner" i-th piece. If a piece is a segment, then a_i = 0 or b_i = 0.
Output
Output file must contain two positive integers W H — the width and height of the frame, with W ≥ H. If the solution does not exist, it should give the number of −1. ЕIf making a few, must issue a decision with the maximum value of W.
Examples
Input #1
Answer #1
Submissions 81
Acceptance rate 6%