George and Accommodation
Practice this coding question on Coding Gurukul.
Problem statement
Two visiting students want to stay together during a campus workshop. The housing desk has a list of rooms, with the current occupancy and total capacity for each room. Existing residents will not be moved, and the visitors must share one room rather than split across two rooms. Your program helps the desk count how many rooms could accommodate both students immediately. Your task For each of n rooms, read p, the number of current occupants, and q, the capacity. Count the rooms for which at least two unused places remain. Each room contributes either one or zero to the answer, regardless of how many additional spare places it has. Important details A room with exactly two free places qualifies. A room with one free place does not. Occupancies are guaranteed not to exceed capacities, and an empty room is evaluated by the same rule. Worked example The rooms (1,3), (2,3), (0,2) and (5,5) have 2, 1, 2 and 0 free places. Only the first and third qualify, giving 2.
Input format
First line: n. Next n lines: p q.
Output format
Print the number of suitable rooms.
Constraints
1 <= n <= 100; 0 <= p <= q <= 100.
Sample input
4 1 3 2 3 0 2 5 5
Sample output
2
Sign in to run or submit a solution in C++, Java or Python.