Intelligent Train 2
InterviewTime limit1sMemory limit128 MB
Given boarding and alighting counts at 10 stations, simulate the running passenger total and print its maximum value.
- Level
Easy2 of 10
- Topics
- Simulation, Array
- Solved
- No attempts yet
Problem
An intelligent train runs through 10 stations from station 1 (departure) to station 10 (terminal) in order. At each station, a device records how many passengers get off and how many get on. Passengers always board only after everyone who wants to get off has left.
The records for all 10 stations satisfy these conditions.
- The train visits stations in increasing station-number order.
- Nobody gets off at the departure station, and nobody gets on at the terminal station.
- At no station do more passengers get off than are currently on the train.
- The train capacity is 10,000 passengers, and it is never exceeded.
After subtracting the number getting off and then adding the number getting on at each station, find the maximum number of passengers that were on the train at any point during the trip.
Input
Ten lines are given, one for each station in order from the first station to the tenth. Each line contains two space-separated integers: the number of passengers who get off and the number of passengers who get on at that station.
Output
Print the maximum number of passengers that were on the train during the trip.