Created
May 24, 2010 11:42
-
-
Save u1ik/411778 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// solution for CF14 problem B: http://codeforces.com/contest/14/problem/B?locale=en | |
open System | |
let split (s: string) = s.Split([|' '|]) | |
let ints() = [for s in Console.ReadLine() |> split -> int s] | |
let [n;x0] = ints() | |
let segments = [for i in {1..n} -> ints() |> List.sort] | |
let points = x0::(List.concat segments) | |
let okay x = List.forall (fun [a;b]-> a <= x && x <= b) segments | |
let good = List.filter okay points | |
let x = if List.length good = 0 then -1 | |
else List.min ([for p in good -> abs (p-x0)]) | |
printf "%d\n" x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment