PROBLEM LINK:
Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4
Author: iceknight1093
Tester: sushil2006
Editorialist: iceknight1093
DIFFICULTY:
Cakewalk
PREREQUISITES:
None
PROBLEM:
Chef has won X Grand Slams. He want to win at least 25, and can win 4 every year.
How many year will he need?
EXPLANATION:
Chef has X Slams now, and wants to reach 25.
That means he needs at least 25-X more of them.
Every year can give four, so the answer is the smallest k such that 4\cdot k \geq 25 - X.
To find this value of k, you can either iterate over k starting from 0, or do a bit of math and notice that:
4\cdot k \geq 25 - X \iff k \geq \frac{25-X}{4}
So, we want the smallest integer that’s at least \frac{25-X}{4}, which by definition is
\text{ceil}\left(\frac{25-X}{4}\right)
Here, \text{ceil} is the ceiling function.
TIME COMPLEXITY:
\mathcal{O}(1) per testcase.
CODE:
Editorialist's code (PyPy3)
x = int(input())
req = 25 - x
print((req + 3) // 4)