IPLTRSH - Editorial

PROBLEM LINK:

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

Authors: d_k_7386
Tester: tabr
Editorialist: iceknight1093

DIFFICULTY:

273

PREREQUISITES:

None

PROBLEM:

N students want to attend a cricket match that has M tickets available. How many of them will miss out?

EXPLANATION:

If M \geq N, then all the students can buy tickets, so the answer is 0.
If M \lt N, then N-M of the students won’t be able to buy tickets.

This can be succinctly represented by the formula \max(0, N-M).

TIME COMPLEXITY

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

CODE:

Editorialist's code (Python)
for _ in range(int(input())):
    n, m = map(int, input().split())
    print(max(0, n - m))

public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int testcase = input.nextInt();
while (testcase-- > 0) {
int students = input.nextInt();
int ticketsAvailable = input.nextInt();
if (ticketsAvailable < students){
System.out.println(students - ticketsAvailable);
}else {
System.out.println(0);
}
}
}