PIZZAPARTY - Editorial

PROBLEM LINK:

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

Author: raysh07
Tester: sushil2006
Editorialist: iceknight1093

DIFFICULTY:

Cakewalk

PREREQUISITES:

None

PROBLEM:

Chef is hosting a pizza party, with A of his friends being boys and B girls. Chef is also a boy.
Each boy eats 4 slices of pizza, each girl eats 3, and each pizza has 8 slices.
How many pizzas does Chef need to have enough slices?

EXPLANATION:

Chef is a boy, so including Chef, there are A+1 bots and B girls.
This means the total number of pizza slices needed is

4\times (A+1) + 3\times B

Each pizza has 8 slices, so to obtain the number of pizzas required we can divide this quantity by 8; rounding up if it isn’t perfectly divisible.

One easy way to represent this is with the ceiling function, with which the answer is simply

\left\lceil \frac{4\cdot (A+1) + 3\cdot B}{8} \right\rceil

TIME COMPLEXITY:

\mathcal{O}(1) per testcase.

CODE:

Editorialist's code (PyPy3)
a, b = map(int, input().split())
slices = 4*(a+1) + 3*b
print((slices + 7) // 8)