Great City Saint Petersburg
시간 제한5초메모리 제한2048 MB
담장 사이에 고이는 빗물의 양을 구하고, 구간 높이 증가가 일어날 때마다 갱신된 총량을 출력하는 문제입니다.
문제
Saint Petersburg is the most beautiful city in the world unless it is raining. For the sake of this problem, we will assume it is raining every single day.
One of the streets in Saint Petersburg has an unusual shape --- it is a narrow stripe of sections meter long each, where section is at the height meters from the ground. The stripe is meter deep and bounded on the front and on the back by incredibly high buildings. Because of this, when it is raining, a certain amount of rain will accumulate, unable to flow out of the street from either its leftmost or rightmost end. Given the heights , , \ldots, , you need to determine the amount of rain (in cubic meters) which will accumulate on the street.
Moreover, your colleagues from the metropolitan construction company will be visiting for days and on day they will be laying asphalt on all sections from to inclusive, thus increasing the height of each section , , \ldots, by meter. You need to determine the total amount of water which accumulates on the street before the construction works, and also after every single day of the construction works.
입력
The first line contains the number of blocks and the number of construction events (). The second line contains integers () --- the height of each section before all the events. Each of the following lines contains a pair of integers , (), denoting the construction work from to inclusive.
출력
Print integers --- the amount of water on the street before all updates, and also after every update.
힌트
The picture illustrates the amount of water accumulating on the street in the first example.
