Skip to content

Commit

Permalink
43-gjsk132
Browse files Browse the repository at this point in the history
  • Loading branch information
gjsk132 committed Nov 3, 2024
1 parent e5f1289 commit 70c3c10
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions gjsk132/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 70c3c10

Please sign in to comment.