No.2208 Linear Function
タグ : / 解いたユーザー数 290
作問者 :
Problem Statement
You are given integers $L, R, A, B$. Find the maximum possible value of the function $f(x) = Ax + B$ defined for real numbers $x$ satisfying $L \leq x \leq R$.
You are given $T$ test cases; solve each of them.
Constraints
- All input values are integers
- $1 \leq T \leq 1000$
- $-1000 \leq L \leq R \leq 1000$
- $-1000 \leq A, B \leq 1000$
Input
The input is given from standard input in the following format.
$T$
$\mathrm{case}_1$
$\mathrm{case}_2$
$\vdots$
$\mathrm{case}_T$
Each test case is given in the following format.
$L$ $R$ $A$ $B$
Output
Print $T$ lines. On the $i$-th line, print the answer to the $i$-th test case. It can be proved that the answer is an integer under the constraints of this problem, so print it as an integer.
Sample
Sample 1
Input
3 1 3 2 6 -1 6 -3 7 2 2 -1000 1
Output
12 10 -1999
Test case $1$: The function $f(x) = 2x + 6$ defined on the interval $1 \leq x \leq 3$ attains its maximum value $f(3) = 12$ at $x = 3$, so the answer is $12$.
Test case $2$: The function $f(x) = -3x + 7$ defined on the interval $-1 \leq x \leq 6$ attains its maximum value $f(-1) = 10$ at $x = -1$, so the answer is $10$.
Test case $3$: The function $f(x) = -1000x + 1$ defined on the interval $2 \leq x \leq 2$ attains its maximum value $f(2) = -1999$ at $x = 2$, so the answer is $-1999$.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。