Bus
InterviewTime limit1sMemory limit1024 MB
Track how many passengers are on the bus after each stop and report the largest number of them that exceeds the seat count K.
- Level
Easy3 of 10
- Topics
- Implementation, Simulation, Array
- Solved
- No attempts yet
Problem
A bus route consists of stops. The bus reaches the first stop straight from the depot, so it is always empty when it arrives there. After that, at each stop some passengers board the bus and some passengers get off.
Passengers prefer to sit down: whenever there is a free seat on the bus a passenger will take it, and passengers stand only when there is not a single free seat left. The bus has seats in total.
Given how many passengers board and get off at every stop, find the greatest number of passengers that ever have to stand in the bus at one time.
Input
The first line contains two integers and — the number of stops on the route and the number of seats in the bus.
Each of the next lines contains two integers and : is the number of passengers boarding at that stop, and is the number getting off.
Output
Print a single integer — the maximum number of passengers that ever have to stand in the bus at one time.