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

There are X grams of ice cream.
Each minute, Y grams will melt.
How much is left after N minutes?

EXPLANATION:

After N minutes, with Y grams lost per minute, a total of N\cdot Y grams will be lost.

So,

  • If N\cdot Y \le X, the remaining ice cream amount is
    X - N\cdot Y
  • If N\cdot Y \gt X, all the ice cream will melt, so the remaining amount is 0.

This can be checked using an if condition, or combined into a single expression as

\max(0, X - N\cdot Y)

TIME COMPLEXITY:

\mathcal{O}(1) per testcase.

CODE:

Editorialist's code (PyPy3)
for _ in range(int(input())):
    x, y, n = map(int, input().split())
    print(max(0, x - n*y))