2022 J5 - Square Pool
Hardbrute forceimplementation
1 Solution Available
Solution 1
PYTHON1n = int(input())
2t = int(input())
3
4trees = []
5
6for i in range(t):
7 r, c = map(int, input().split())
8 trees.append([r, c])
9
10posleft = [1]
11postop = [1]
12
13for tr, tc in trees:
14 posleft.append(tc+1)
15 postop.append(tr+1)
16
17def getMax(treeR, treeC):
18 maxW = n-treeC+1
19 maxH = n-treeR+1
20
21 for tr, tc in trees:
22 if tr >= treeR and tc >= treeC:
23 tr -= treeR
24 tc -= treeC
25 if tr > tc:
26 maxH = min(maxH, tr)
27 else:
28 maxW = min(maxW, tc)
29
30 return min(maxW, maxH)
31
32ans = 0
33for treeR in postop:
34 for treeC in posleft:
35 ans = max(ans, getMax(treeR, treeC))
36
37print(ans)Test Cases
Select a test case to view input and output