MAXIMUM PRODUCTION (EITA) - Codechef solution in C++ language

  

MAXIMUM PRODUCTION

Problem Code: EITA


Chefland has 7 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  (<7) 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

  • 1<7
  • 1<<18

Example

Input:
3
1 2 3 1
6 2 3 1
1 2 8 1
Output:
14
19
14

Explanation:

Test Case 1: Using the first strategy, Chef does 27=14 units of work and using the second strategy Chef does 31+16=9 units of work. So the maximum amount of work that Chef can do is max(14,9)=14 units by using the first strategy.

Test Case 2: Using the first strategy, Chef does 27=14 units of work and using the second strategy Chef does 36+11=19 units of work. So the maximum amount of work that Chef can do is max(14,19)=19 units by using the second strategy.

. . .

Solution in C++.


#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin >> t;
	while(t--){
	   int d, x, y, z;
	   cin >> d >> x >> y >> z;
	   int ans = x*7;
	   int res = (y*d + z*(7-d));
	   int max = ans>res?ans:res;
	   cout << max << endl;
	}
	return 0;
}


            Try Solution On The C-Playground : https://bit.ly/45BxlGA

Comments

Popular posts from this blog

ATM solution in C language.- Codechef

MOTIVATION SOLUTION IN C LANGUAGE | CODECHEF | IMDB

APPLE AND ORANGE | HACKERRANK | PROBLEM SOLVING | SOLUTION IN C