diff --git a/gjsk132/README.md b/gjsk132/README.md index 10725b8..fddc319 100644 --- a/gjsk132/README.md +++ b/gjsk132/README.md @@ -41,3 +41,4 @@ | 39차시 | 2024.05.29 | Dijkstra | [11781 퇴근 시간](https://www.acmicpc.net/problem/11781) | [🚌](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/183) | | 40차시 | 2024.06.04 | BitMasking | [[1차] 비밀지도](https://school.programmers.co.kr/learn/courses/30/lessons/17681) | [🗺️](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/190) | | 41차시 | 2024.07.01 | TSP | [2098 외판원 순회](https://www.acmicpc.net/problem/2098) | [✈️](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/195) | +| 43차시 | 2024.11.03 | Two Pointer | [20366 같이 눈사람 만들래?](https://www.acmicpc.net/problem/20366) | [☃️](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/234) | \ No newline at end of file diff --git "a/gjsk132/Two Pointer/20355 \352\260\231\354\235\264 \353\210\210\354\202\254\353\236\214 \353\247\214\353\223\244\353\236\230.py" "b/gjsk132/Two Pointer/20355 \352\260\231\354\235\264 \353\210\210\354\202\254\353\236\214 \353\247\214\353\223\244\353\236\230.py" new file mode 100644 index 0000000..e3e618a --- /dev/null +++ "b/gjsk132/Two Pointer/20355 \352\260\231\354\235\264 \353\210\210\354\202\254\353\236\214 \353\247\214\353\223\244\353\236\230.py" @@ -0,0 +1,51 @@ +input = open(0).readline + +n = int(input()) + +snow = sorted(list(map(int,input().split()))) + +min_gap_height = float("inf") + +target = 0 + +def two_pointer(block1, block2): + start, end = 0, n-1 + + target = snow[s1] + snow[s2] + + min_gap = target + + while not start == end: + if start == block1 or start == block2: + start += 1 + continue + + if end == block1 or end == block2: + end -= 1 + continue + + height = snow[start] + snow[end] + + min_gap = min(min_gap, abs(target-height)) + + if height > target: + end -= 1 + else: + start += 1 + return min_gap + + +answer = snow[0] + snow[n-1] + +for s1 in range(n-1): + + if not answer: + break + + for s2 in range(s1+1, n): + answer = min(answer, two_pointer(s1, s2)) + + if not answer: + break + +print(answer)