Untitled

mail@pastecode.io avatar
unknown
python
2 years ago
1.3 kB
2
Indexable
Never
import math
import os
import re
import sys
import random

def maxHeight(wallPositions,wallHeights):
    n=len(wallPositions)
    mud_max=0
    for i in range(0,n-1):
        if wallPositions[i]<(wallPositions[i+1]-1):
            heightDiff=abs(wallHeights[i+1]-wallHeights[i])
            gapLen=wallPositions[i+1]-wallPositions[i]-1
            localMax=0
            if gapLen>heightDiff: 
                low=max(wallHeights[i+1],wallHeights[i])+1
                remainingGap=gapLen-heightDiff-1
                localMax=low+remainingGap/2
            else:
                localMax=min(wallHeights[i+1],wallHeights[i])+gapLen
            mud_max=max(mud_max,localMax)
    return int(mud_max)
if _name=='main_':
    fptr=open(os.environ['OUTPUT_PATH'],'w')
    wallPositions_count=int(input().strip())
    wallPositions=[]
    for _ in range(wallPositions_count):
        wallPositions_item=int(input().strip())
        wallPositions.append(wallPositions_item)
    wallHeights_count=int(input().strip())
    wallHeights=[]
    for _ in range(wallHeights_count):
        wallHeights_item=int(input().strip())
        wallHeights.append(wallHeights_item)
    result=maxHeight(wallPositions,wallHeights)
    fptr.write(str(result)+'\n')
    fptr.close()