SANDWICH7 - Editorial

PROBLEM LINK:

Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4

Author: raysh07
Tester: iceknight1093
Editorialist: iceknight1093

DIFFICULTY:

TBD

PREREQUISITES:

None

PROBLEM:

A sandwich requires two slices of bread, and either one slice of ham or one slice of cheese.

You have B slices of bread, H of ham, and C of cheese.
How many sandwiches can you create?

EXPLANATION:

Each sandwich needs two slices of bread, so the number we can make is limited by half the number of bread slices, rounded down, i.e.

\left\lfloor\frac{B}{2} \right\rfloor

Each sandwich needs either ham or cheese, so we’re also limited by the total number of slices of these, i.e. by

H+C

Since both limitations are active, the stricter one among them is what matters - thus the answer is

\min\left(H+C, \left\lfloor\frac{B}{2} \right\rfloor\right)

TIME COMPLEXITY:

\mathcal{O}(1) per testcase.

CODE:

Editorialist's code (PyPy3)
b, h, c = map(int, input().split())
print(min(b//2, h+c))