Two Fridges

Time limit: 300 ms
Memory limit: 256 MB

Dexter is playing again with NN substances trying to complete his greatest invention. Because it's running late, Dexter has decided the invention will have to wait until tomorrow. In the meanwhile, he needs to find a way to store the NN substances in his two fridges. Each fridge can be set to a certain temperature, an integer value between 100-100 and 100100. For each of the NN substances, Dexter knows an interval [ai,bi][a_i, b_i], meaning the storing temperature of the ii-th substance needs to fall in that specific interval.

Help Dexter decide the temperatures of the two fridges.

Standard input

The first line contains a single integer NN.

Each of the following NN lines contains two values aia_i and bib_i, representing the storing interval for the ii-th substance.

Standard output

If there is no solution, print 1-1.

Otherwise, print two values T1T_1 and T2T_2 (T1T2T_1 \leq T_2), representing the temperatures of the two fridges.

Constraints and notes

  • 0N1000 \leq N \leq 100
  • 100aibi100-100 \leq a_i \leq b_i \leq 100
  • 100T1T2100-100 \leq T_1 \leq T_2 \leq 100
  • If there are multiple solutions, print the one where T1T_1 is minimum. If there are still multiple solutions, print the one where T2T_2 is minimum.

InputOutputExplanation
2
10 12
20 24
10 20

Each substance will be stored in a separate fridge.

4
-54 -40
-50 -42
36 77
49 100
-50 49

The first two substances will be stored in the first fridge, while the last two substances will be stored in the second fridge.

Authenticate to use the workspace

Log In
Sign Up
Forgot Password?
or connect with