💡문제접근
- for문을 통한 이중 반복문으로 두 개의 스티커를 선택한 다음 총 4가지의 경우를 고려해서 문제를 해결했다. 머릿속으로는 이해했지만 코드로 구현하는 과정에서 많은 시간이 걸렸던 문제였다.
💡코드(메모리 : 31256KB, 시간 : 52ms)
import sys
input = sys.stdin.readline
H, W = map(int, input().strip().split())
N = int(input())
sticker = [list(map(int, input().strip().split())) for _ in range(N)]
Max = -1
for i in range(N):
r1, c1 = sticker[i]
for j in range(i+1, N):
r2, c2 = sticker[j]
if (r1 + r2 <= H and max(c1, c2) <= W) or (max(r1, r2) <= H and c1 + c2 <= W):
Max = max(Max, (r1 * c1) + (r2 * c2))
if (r2 + c1 <= H and max(r1, c2) <= W) or (max(c1, r2) <= H and r1 + c2 <= W):
Max = max(Max, (r1 * c1) + (r2 * c2))
if (r1 + c2 <= H and max(c1, r2) <= W) or (max(r1, c2) <= H and c1 + r2 <= W):
Max = max(Max, (r1 * c1) + (r2 * c2))
if (c1 + c2 <= H and max(r1, r2) <= W) or (max(c1,c2) <= H and r1 + r2 <= W):
Max = max(Max, (r1 * c1) + (r2 * c2))
if Max == -1:
print(0)
else:
print(Max)
💡소요시간 : 47m