Tram

Practice this coding question on Coding Gurukul.

Problem statement

A campus shuttle makes a fixed sequence of stops. It begins empty, and at each stop some passengers leave before new passengers board. The transport office wants the smallest vehicle capacity that could carry everyone on this journey without exceeding the seat limit at any point. The records describe a valid journey, so passengers never leave a shuttle they were not already riding. Your task Process each stop in order. Subtract the departing passengers from the current occupancy, then add the boarding passengers. Track the largest occupancy reached during the journey and print that maximum as the required capacity. Passengers are not reserved for later stops; only simultaneous occupancy matters. Important details The first stop has no departing passengers and the final stop leaves the shuttle empty. Adding every boarding count together overestimates capacity because seats can be reused after passengers leave. Worked example For stops (0,3), (1,4), (4,0), (2,0), occupancies after boarding are 3, 6, 2 and 0. The shuttle needs capacity 6.

Input format

First line: n. Next n lines: departing boarding.

Output format

Print the minimum required capacity.

Constraints

2 <= n <= 1000; each count is 0..1000; journey is valid and ends empty.

Sample input

4
0 3
1 4
4 0
2 0

Sample output

6

Sign in to run or submit a solution in C++, Java or Python.