0.SV. Machine
An engineer needs to schedule a machine to run on some given periods 1;..., n to produce a chemical
product C. Each period i is represented by a starting time point s
Input
The input consists the following lines:
? Line 1: contains the positive integer n (2 = < n = < 10^6)
? Line i + 1: contains two positive integer s
Output
The output consists of only one single integer which is the amount of product C the machine will produce in the two selected periods. In case there is no solution (there does not exist two periods that are not overlap), the output contains the value -1.
Example
Input
5
8 12
6 11
3 9
2 5
1 4
Input
8
Explanation
The machine will be runned on two periods [2, 5] and [6, 11] and produce 8 unit of product C.
Comments