FOODPLAN - Editorial

PROBLEM LINK:

Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4

Author: notsoloud
Tester: jay_1048576
Editorialist: iceknight1093

DIFFICULTY:

713

PREREQUISITES:

None

PROBLEM:

Ordering food online costs N rupees but comes with a 10\% discount, while dining at the restaurant costs M rupees.
Which is the cheaper option?

EXPLANATION:

To truly compare the costs, we need to compute the actual cost of ordering online, after the discount is applied.
Since, the discount is of 10\%, the cost of ordering online is N - \frac{N}{10} = \frac{9N}{10}

So,

  • If \frac{9N}{10} \lt M, ordering online is cheaper.
  • If \frac{9N}{10} \gt M, dining is cheaper.
  • If \frac{9N}{10} = M, either one is fine.

The constraints are small so doing floating-point computations should get you AC.
However, if you wish to work purely with integers, you can compare the values of 9N and 10M.

TIME COMPLEXITY

\mathcal{O}(1) per test case.

CODE:

Editorialist's code (Python)
for _ in range(int(input())):
    n, m = map(int, input().split())
    x, y = 9*n, 10*m
    if x < y: print('Online')
    elif x > y: print('Dining')
    else: print('Anyone')