Skip to content

Instantly share code, notes, and snippets.

@u1ik
Created May 24, 2010 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save u1ik/411778 to your computer and use it in GitHub Desktop.
Save u1ik/411778 to your computer and use it in GitHub Desktop.
// 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