아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Rain

면접 대비

시간 제한1초메모리 제한1024 MB

요약
건물 높이들이 주어질 때 건물 사이와 위에 고이는 빗물의 총량을 구한다.
난이도

보통10점 중 6점

유형
투 포인터, 배열, 누적 합
정답자
아직 제출이 없습니다

문제

In your city, there is a shortage of drinking water so the city planner is finding more ways to trap rainwater to be used for drinking. The city has varying heights of buildings, and rainwater gets trapped between the buildings. The city planner has asked you to write a program that, given the heights of the buildings, can find the largest amount of rainwater that can get trapped between the buildings.

입력

The first line will contain a single integer n that indicates the number of data sets that follow. Each data set will consist of a single line of integers, denoting the heights of the buildings. The building height can be positive or negative.

출력

Output the total amount of rainwater that can be trapped between/above the buildings of varying height.

예제1

  1. 예제 1

    입력
    2
    5 0 0 0 5
    6 3 1 6 4 5 1 0 3 5 3 1 4
    
    예상 출력
    15
    24