# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
# max water
# @param arr int整型一维数组 the array
# @return long长整型
#
class Solution:
    def maxWater(self , arr: List[int]) -> int:
        # write code here
        l = 0
        r= len(arr)-1

        count = 0
        minl = arr[l]
        minr = arr[r]

        while l<r:
            if minl<minr:
                l+=1
                if arr[l]<minl:
                    count+=minl-arr[l]
                elif arr[l]>minl:
                    minl = arr[l]
            else:
                r-=1
                if arr[r]<minr:
                    count+=minr-arr[r]
                elif arr[r]>minr:
                    minr = arr[r]
        
        return count