PROBLEM LINK:
Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4
Author: Abhinav Sharma
Testers: Nishank Suresh, Nishant Shah
Editorialist: Nishank Suresh
DIFFICULTY:
541
PREREQUISITES:
None
PROBLEM:
Chef bought items worth X rupees, and receives some flat discount on them depending on the value of X. What is the final amount paid by Chef?
EXPLANATION:
This is a standard application of the if-else
condition found in most languages. There are 4 conditions and exactly one of them is true, so check all 4, subtract the available discount, and print the answer.
- If X \leq 100, there is no discount so print X
- Else, if 100 \lt X \leq 1000, print X - 25
- Else, if 1000 \lt X \leq 5000, print X - 100
- Else, print X - 500
TIME COMPLEXITY:
\mathcal{O}(1) per test case.
CODE:
Editorialist's Code (Python)
for _ in range(int(input())):
x = int(input())
if x > 5000:
x -= 500
elif x > 1000:
x -= 100
elif x > 100:
x -= 25
print(x)