PROBLEM 98
Hard

Ticket Booking System

Programming Basics · Python

</>
STATUS Not solved

TASK

Problem

#98

Given free seats `free`, requested `need`, balance, and ticket `price`. Booking succeeds if there are enough seats and enough money. Print `BOOKED` and remaining balance, otherwise `REJECTED`.

EXAMPLE

Example

Input
5 2 1000 300
Output
BOOKED 400

LIMITS

Constraints

Quantities, prices, and balances are integers from 0 to 10^9; other integer inputs have absolute value at most 10^9.
📖
LEARN Theory for this problem
+

`input()` reads data entered by the user. The result of `input()` is initially a string. `split()` separates one input line into individual values using spaces. `map()` applies the specified conversion to each input value. The `-` operator subtracts one number from another. The `*` operator multiplies numbers. Comparison operators `==`, `!=`, `<`, `>`, `<=`, `>=` compare values and produce `True` or `False`. `and` requires all combined conditions to be true. `if` checks a condition and runs its block when the condition is true. `else` runs when the corresponding `if` condition is false. `print()` displays the program result. Print only what the problem statement requires.

**Connection to this task.** An `if` statement chooses a program branch from a Boolean condition. Comparisons produce `True` or `False`, and `elif` lets you test several mutually exclusive cases in order. The expression `'BOOKED'` shows how this idea is applied to the task data.

💡
NEED HELP? Hints
+

['Order cost is `need * price`; then use two checks with `and`.']

ANSWER Solution
+
f, n, b, p = map(int, input().split())
cost = n * p
if n <= f and cost <= b:
    print('BOOKED', b - cost)
else:
    print('REJECTED')