[BOJ] 창고 다각형

Date:

[BOJ] 창고 다각형

Problem URL : 창고 다각형

N = int(input())

pillar = []
maxH = 0

for i in range(N):
    pillar.append(list(map(int, input().split())))
    if maxH < pillar[i][1]:
        maxH = pillar[i][1];

pillar.sort()

area = 0
H1 = 0
W1 = 0

for i in range(N):
    if H1 < pillar[i][1]:
        area += H1 * (pillar[i][0] - W1)
        H1 = pillar[i][1]
        W1 = pillar[i][0]

    if H1 == maxH:
        break

H2 = 0
W2 = 0

for j in range(N - 1, -1, -1):
    if H2 < pillar[j][1]:
        area += H2 * (W2 - pillar[j][0])
        H2 = pillar[j][1]
        W2 = pillar[j][0]

    if H2 == maxH:
        break

area += maxH * (W2 + 1 - W1)

print(area)

댓글