問題一覧 > 通常問題

No.2208 Linear Function

レベル : / AI推定難易度 : 115 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 290
作問者 : Shirotsume / テスター : 👑 AngrySadEight ygussany
お気に入りにしたユーザー ProblemId : 9043 / 自分の提出
問題文最終更新日: 2023-02-09 15:57:46
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 376 (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。