Maximum Production Problem Code: EITA

 

Read problem statements in Bengali, Mandarin Chinese, Russian, and Vietnamese as well.

Chefland has  days in a week. Chef is very conscious about his work done during the week.

There are two ways he can spend his energy during the week. The first way is to do  units of work every day and the second way is to do  () units of work for the first  () days and to do  () units of work thereafter since he will get tired of working more in the initial few days.

Find the maximum amount of work he can do during the week if he is free to choose either of the two strategies.

Input

  • The first line contains an integer , the number of test cases. Then the test cases follow.
  • Each test case contains a single line of input, four integers , , , .

Output

For each testcase, output in a single line the answer to the problem.

Constraints

Subtasks

Subtask #1 (100 points): Original constraints

Sample Input

3
1 2 3 1
6 2 3 1
1 2 8 1

Sample Output

14
19
14

Explanation

Test Case : Using the first strategy, Chef does  units of work and using the second strategy Chef does  units of work. So the maximum amount of work that Chef can do is  units by using the first strategy.

Test Case : Using the first strategy, Chef does  units of work and using the second strategy Chef does  units of work. So the maximum amount of work that Chef can do is  units by using the second strategy.

Comments

Popular posts from this blog

How to pass parameters in webhook?

Access and modify all the resources of our Wiki.js using WikiJS API

Fahrenheit to Celsius