PROBLEM LINK:
Contest Division 1
Contest Division 2
Contest Division 3
Contest Division 4
Setter: Utkarsh Gupta
Tester: Abhinav Sharma, Aryan
Editorialist: Lavish Gupta
DIFFICULTY:
Cakewalk
PREREQUISITES:
None
PROBLEM:
Chef goes to the supermarket to buy some items. Luckily there’s a sale going on under which Chef gets the following offer:
- If Chef buys 3 items then he gets the item (out of those 3 items) having the lowest price as free.
For e.g. if Chef bought 3 items with the cost 6, 2 and 4, then he would get the item with cost 2 as free. So he would only have to pay the cost of the other two items which will be 6 + 4 = 10.
Chef buys 3 items having prices A, B and C respectively. What is the amount of money Chef needs to pay?
EXPLANATION:
We first need to find out the lowest price among A, B and C.
If A is lowest, then Chef needs to pay B + C. Similarly, if B is lowest, Chef will pay A+C and if C is lowest, Chef will pay A+B.
To find out if A is lowest, we can use two if conditions - (A \leq B) AND (A \leq C). We can have similar conditions for B and C.
TIME COMPLEXITY:
O(1) for each test case.
SOLUTION:
Editorialist's Solution
#include<bits/stdc++.h>
#define ll long long
using namespace std ;
int main()
{
ll t;
cin >> t ;
while(t--)
{
ll a , b , c ;
cin >> a >> b >> c ;
if(a <= b && a <= c)
{
cout << b+c << '\n' ;
}
else
{
if(b <= a && b <= c)
cout << a+c << '\n' ;
else
cout << a+b << '\n' ;
}
}
return 0;
}