# YOGACLASS - Editorial

Author: notsoloud
Tester: airths
Editorialist: iceknight1093

TBD

None

# PROBLEM:

Chef can teach a 1-hr class for X rupees, or a 2-hr class for Y rupees.
What’s the maximum amount of money Chef can earn in N hours?

# EXPLANATION:

Note that if 2\cdot X \geq Y, Chef will earn more by holding two 1-hr classes rather than a single 2-hr class.

So,

• If 2\cdot X \geq Y, Chef will never hold a 2-hr class.
His total earnings will be N\cdot X.
• If 2\cdot X \lt Y, it’s always better for Chef to hold a 2-hr class when possible.
So,
• If N is even, Chef will hold \frac{N}{2} 2-hr classes, earning Y\cdot \frac{N}{2} in total.
• If N is odd, Chef will hold \left\lfloor\frac{N}{2}\right\rfloor 2-hr classes, and then a single 1-hr class, earning Y\cdot \left\lfloor\frac{N}{2}\right\rfloor + X in total.

# TIME COMPLEXITY:

\mathcal{O}(1) per testcase.

# CODE:

Editorialist's code (Python)
for _ in range(int(input())):
n, x, y = map(int, input().split())
ans = x*(n%2) + (n//2)*max(y, 2*x)
print(ans)

1 Like