#45789: 求援助(75%)


linswater (linswater)


n = int(input(""))
w1,w2,h1,h2 = list(map(int,input("").split()))
volume = [int(n) for n in input("").split()]
a = [w1**2,w2**2]
h = [h1,h2]
delta = []
for vol in volume:
    height = vol/a[0]
    if height < h[0]:
        delta.append(height)
        h[0] -= height
    elif height >= h[0]:
        if len(a) == 2:
            extra = (a[0]*(height-h[0]))/a[1]
            delta.append(h[0]+ extra)
            a.pop(0)
            h.pop(0)
            h[0] -= extra
        else:
            delta.append(h[0])
            break
print(int(max(delta)))
#45790: Re: 求援助(75%)


leeguanhan0909@gmail.com (李冠翰)


n = int(input(""))
w1,w2,h1,h2 = list(map(int,input("").split()))
volume = [int(n) for n in input("").split()]
a = [w1**2,w2**2]
h = [h1,h2]
delta = []
for vol in volume:
    height = vol/a[0]
    if height < h[0]:
        delta.append(height)
        h[0] -= height
    elif height >= h[0]:
        if len(a) == 2:
            extra = (a[0]*(height-h[0]))/a[1]
            delta.append(h[0]+ extra)
            a.pop(0)
            h.pop(0)
            h[0] -= extra
        else:
            delta.append(h[0])
            break
print(int(max(delta)))

在計算extra時要考慮是否超過h[1]

#45855: Re: 求援助(75%)


linswater (linswater)


n = int(input(""))
w1,w2,h1,h2 = list(map(int,input("").split()))
volume = [int(n) for n in input("").split()]
a = [w1**2,w2**2]
h = [h1,h2]
delta = []
for vol in volume:
    height = vol/a[0]
    if height < h[0]:
        delta.append(height)
        h[0] -= height
    elif height >= h[0]:
        if len(a) == 2:
            extra = (a[0]*(height-h[0]))/a[1]
            delta.append(h[0]+ extra)
            a.pop(0)
            h.pop(0)
            h[0] -= extra
        else:
            delta.append(h[0])
            break
print(int(max(delta)))

在計算extra時要考慮是否超過h[1]

謝謝回應