SWEETSHOP - 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:

Sushil had X rupees, but bought N laddus worth Rs. 10 each.
How many jalebis can he buy with the remaining money, if they cost Rs. 20 each?

EXPLANATION:

Sushil started with X, and bought N laddus worth 10 each.
This means he’s left with

X - 10N

rupees.

Each jalebi costs 20, so with the remaining money, he can purchase a total of

\left\lfloor \frac{X-10N}{20} \right\rfloor

jalebis.

Here, \left\lfloor y \right\rfloor denotes the floor of x, that is, the largest integer that doesn’t exceed y.
In C++ and Java this is what the division operator / does when working on integers, while in Python you’ll need to specify it using //.

TIME COMPLEXITY:

\mathcal{O}(1) per testcase.

CODE:

Editorialist's code (PyPy3)
x, n = map(int, input().split())
remaining = x - n*10
print(remaining // 20)