Maximum Production Codechef Solution

Maximum Production Codechef Solution

Chefland has 77 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 xx units of work every day and the second way is to do yy (>x>x) units of work for the first dd (<7<7) days and to do zz (<x<x) 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.

See Also : July Long Challenge 2021 Solutions Codechef

Input

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

Output

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

Constraints

  • 1≤T≤5⋅1031≤T≤5⋅103
  • 1≤d<71≤d<7
  • 1≤z<x<y≤181≤z<x<y≤18

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 11: Using the first strategy, Chef does 2⋅7=142⋅7=14 units of work and using the second strategy Chef does 3⋅1+1⋅6=93⋅1+1⋅6=9 units of work. So the maximum amount of work that Chef can do is max(14,9)=14max(14,9)=14 units by using the first strategy.

Test Case 22: Using the first strategy, Chef does 2⋅7=142⋅7=14 units of work and using the second strategy Chef does 3⋅6+1⋅1=193⋅6+1⋅1=19 units of work. So the maximum amount of work that Chef can do is max(14,19)=19max(14,19)=19 units by using the second strategy.

Solution’s will be post with explanation. Join Us on Telegram for update

Explanation

Credit : Coder Guy

Solution

Program Python:

t=int(input())
for _ in range(t):
    d,x,y,z = map(int,input().split())
    a= x*7
    b= (y*d + (7-d)*z)
    print(max(a,b))
    

July Long Challenge 2021 Solutions

Weekly Contest 247

Biweekly Contest 55

Codechef Long Challenge Solutions

June Long Challenge 2021 Solutions

March Long Challenge 2021 Solutions

April Long Challenge 2021 Solutions

February Long Challenge 2021

January Long Challenge 2021

November Challenge 2020 SOLUTION CodeChef

October Lunchtime 2020 CodeChef SOLUTIONS

Leave a Comment

error: Content is protected !!
Please Click on 1 or 2 Ads to help us run this site.