CALINTAKE - 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 wants to consume at most X calories everyday.
Today, he ate Y sweets each with Z calories. How many more calories can he consume today, or has he already crossed his limit?

EXPLANATION:

Y sweets with Z calories each is a total of Y\cdot Z calories Chef has consumed already.

If Y\cdot Z \gt X, Chef has already gone over his limit and the answer is -1.
Otherwise, he can consume

X - Y\cdot Z

more calories today while not exceeding his limit.

TIME COMPLEXITY:

\mathcal{O}(1) per testcase.

CODE:

Editorialist's code (PyPy3)
x, y, z = map(int, input().split())
if y*z > x: print(-1)
else: print(x - y*z)

This topic was automatically closed after 2 hours. New replies are no longer allowed.

This topic was automatically opened after 1 minute.