Finding Mino

3.7

3 votes
Searching algorithm, Ternary search, Very-Easy
Problem

You have been given an Unimodal function:
f(x)=2x212x+7
with N intervals. For each interval you will be given two integer values l and r , where lr and you need to find the minimum value of f(x) where x will be in the range [l,r] (both inclusive).

Input:
The first line will consists of one integer N denoting the number of intervals.
In next N lines, each line contains 2 space separated integers, l and r denoting the range of interval.

Output:
Print N lines, where ith line denotes the minimum value of f(x), where x will be in range [li,ri]
.

Constraints:
1N105
106lr106

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Here l=6 and r=8.
As f(6)=7, f(7)=21, f(8)=39. So the answer is 7.

Editor Image

?