304 North Cardinal St.
Dorchester Center, MA 02124

# Chef and Spells CodeChef Solution

## Problem – Chef and Spells CodeChef Solution

Chef has three spells. Their powers are AB, and C respectively. Initially, Chef has 0 hit points, and if he uses a spell with power P, then his number of hit points increases by P.

Before going to sleep, Chef wants to use exactly two spells out of these three. Find the maximum number of hit points Chef can have after using the spells.

### Input Format

• The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
• The first and only line of each test case contains three space-separated integers AB, and C.

### Output Format

For each test case, print a single line containing one integer — the maximum number of hit points.

### Constraints

• 1≤T≤10^4
• 1≤A,B,C≤10^8

Subtask #1 (100 points): original constraints

### Sample 1:

``````Input:
2
4 2 8
10 14 18
Output:
12
32``````

### Explanation:

Example case 1: Chef has three possible options:

• Use the first and second spell and have 4+2=6 hitpoints.
• Use the second and third spell and have 2+8=10 hitpoints.
• Use the first and third spell and have 4+8=12 hitpoints.

Chef should choose the third option and use the spells with power 4 and 8 to have 12 hitpoints.

Example case 2: Chef should use the spells with power 14 and 18.

## Chef and Spells CodeChef Solution in C++17

``````#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main()
{
int t;
cin >> t;
while (t--)
{

ll a,b,c,d;
cin >> a >> b >> c;

if(a>b)
{
if(b>c)
{
d=a+b;
}
else
{
d=a+c;
}
}
else
{
if(a>c)
{
d=b+a;
}
else
{
d=b+c;
}
}
cout << d << endl;
}
return 0;
}``````

## Chef and Spells CodeChef Solution in Pyth 3

``````# cook your dish here
for _ in range(int(input())):
l=list(map(int,input().split()))
l.sort()
print(l[-1]+l[-2])
``````

## Chef and Spells CodeChef Solution in Java

``````/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int i=0;i<t;i++)
{
int a=sc.nextInt();
int b=sc.nextInt();
int c=sc.nextInt();
int x=a+b;
int y=b+c;
int z=a+c;
if(x>y && x>z)
{
System.out.println(x);
}
else if(y>=x && y>=z)
{
System.out.println(y);
}
else
{
System.out.println(z);
}
}
}
}
``````
##### Chef and Spells CodeChef Solution Review:

In our experience, we suggest you solve this Chef and Spells CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the Chef and Spells CodeChef Solution

Find on CodeChef

##### Conclusion:

I hope this Chef and Spells CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.

Keep Learning!

More Coding Solutions >>

LeetCode Solutions

Hacker Rank Solutions

CodeChef Solutions