import java.util.Scanner import scala.annotation.tailrec object Problem180 { def ugliness(AB: Seq[(Int, Int)], tab: Long): Long = { val width: Seq[Long] = AB.map(x => x._1 + x._2 * tab) width.max - width.min } @tailrec def search(AB: Seq[(Int, Int)], left: Long, right: Long): Int = { if (left == right) return ((right + left) * 0.5).toInt val nextLeft: Long = (left * 2 + right) / 3 val nextRight: Long = (left + right * 2) / 3 if (ugliness(AB, nextLeft) <= ugliness(AB, nextRight)) { search(AB, left, nextRight) } else { search(AB, nextLeft + 1, right) } } def proc(AB: Seq[(Int, Int)]): Long = { search(AB, 1, Math.pow(10, 9).toLong + 1) } def main(args: Array[String]) { val sc = new Scanner(System.in) val N = sc.nextInt() val AB = Seq.fill(N)(sc.nextInt(), sc.nextInt()) val result = proc(AB) println(result) } }