Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Chef has three spells. Their powers are A, B, 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.
For each test case, print a single line containing one integer — the maximum number of hit points.
Subtask #1 (100 points): original constraints
Input:
2
4 2 8
10 14 18
Output:
12
32
Example case 1: Chef has three possible options:
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.
#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;
}
# cook your dish here
for _ in range(int(input())):
l=list(map(int,input().split()))
l.sort()
print(l[-1]+l[-2])
/* 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
{
// your code goes here
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);
}
}
}
}
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
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 >>