Cab Services
Tag(s):

Easy-Medium

Problem
Editorial
Analytics

You recently came up with a Start-up Idea - You have contacts with various cab services and you provide your clients the cheapest cab.

There are N cab services. Each has a base fare b[i] and additional cost for every kilometer a[i].

You need to print the minimum cost by wisely choosing appropriate cab service.

Input Format:-
First line of input is a single integer N - number of cab services.
Next N lines consists of 2 space-separated integers b[i] and a[i].
Next line contain an integer Q denoting the number of queries.
Q lines follows - each containing a single integer X - number of kilometers to be travelled.

Output Format:-
Output a single integer per test case denoting the minimum cost by selecting appropriate cab service.

Constraints:-
1 ≤ N,Q$10^{5}$
0 ≤ a[i],b[i]$10^{4}$
0 ≤ X$10^{5}$

SAMPLE INPUT
4
1 5
10 3
20 2
40 1
5
4
5
6
12
21
SAMPLE OUTPUT
21
25
28
44
61
Explanation

For first query, First cab service costs 5x4+1 = 21
Second cab service costs 3x4+10 = 22
Third cab service costs 2x4+20 = 28
Fourth cab service costs 1x4+40 = 44

So the minimum cost for first query is 21.
Similarly for other queries.

Time Limit: 1.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: Bash, C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Swift-4.1, TypeScript, Visual Basic

CODE EDITOR

Initializing Code Editor...