 # TOMDESSERTS Editorial

Tom and Desserts - Editorial

Author : R Shyam Sundar (shyam1909)

Difficulty : Cakewalk
Prerequisities : None

Problem:

Tom has 3 different types of desserts.

Type – A : Untasty dessert that could relinquish tom if he is dizzy.

Type – B : Tasty dessert that could relinquish tom if he is dizzy.

Type – C : Tasty dessert that makes tom dizzy. If he is dizzy, he falls asleep.

What is the maximum number of tasty desserts that tom could eat without falling asleep?

Logic:

Tom should eat a dessert of Type-A or Type-B immediately after eating Type-C dessert. If the number of desserts of Type-C is zero left, then he should eat the remaining Type-B desserts.

If there is no Type-A or Type-B dessert to eat after eating Type-C dessert, Tom should stop at this moment.

Calculate the number of tasty deserts (Type B,C) eaten.

Now this logic can be transformed into if-else statements, given the number of desserts of type A,B,C.

Approach:

#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;

void solve()
{
ll a,b,c;
cin >> a >> b >> c;
if(c > a)
{
ll ans = 0;
ans += a;
c -= a;
if(c > b)
{
cout << (ans + (2 * b) + 1) << “\n”;
return;
}
else if(c == b)
{
cout << (ans + (2 * b)) << “\n”;
return;
}
else
{
cout << (ans + (2 * c) + (b - c)) << “\n”;
return;
}
}
else if(c == a)
{
cout << (c + b) << “\n”;
return;
}
else // c < a
{
cout << (c + b) << “\n”;
return;
}
}
int main()
{
int t;
cin >> t;
while(t–)
{
solve();
}
return 0;
}

Source code as png: