PROBLEM LINK:
Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4
Author: raysh07
Tester: sushil2006
Editorialist: iceknight1093
DIFFICULTY:
TBD
PREREQUISITES:
None
PROBLEM:
Chef bought N Christmas trees for A rupees each, and sold M of them for B rupees each.
Find his overall profit.
EXPLANATION:
Buying N trees for A rupees each is an expenditure of N\cdot A rupees.
Selling M trees for B rupees each gives an income of M\cdot B rupees.
Thus, Chef’s overall profit, which is equal to his income minus his spending, is
M\cdot B - N\cdot A
TIME COMPLEXITY:
\mathcal{O}(1) per testcase.
CODE:
Editorialist's code (PyPy3)
n, a, m, b = map(int, input().split())
print(m*b - n*a)