Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์š”๊ฑฐ ์ดˆ๊ธฐ๊ฐ’์„ ์ด๋Ÿฐ ์‹์œผ๋กœ ์„ค์ •ํ•˜๋ฉด

4
1 2 3 999

answer: 995
output: 3

์ด๋Ÿฐ ์‹์œผ๋กœ ์ถœ๋ ฅ๋ฉ๋‹ˆ๋‹น. ์ดˆ๊ธฐ๊ฐ’ ์„ค์ •์„ ๋‹ค์‹œ ๊ณ ๋ฏผํ•ด๋ณผ๊นŒ์š”!?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์˜คํ˜ธ ๊ฐ์‚ฌํ•จ๋‹ˆ๋‹น

min_gap = float('inf')

๊ทผ๋ฐ ์ด์ •๋„๋ฉด ์น˜๋ช…์ ์ธ๋ฐ ์–ด์บ ๋งž์ท„์ง€ ํ…Œ์ผ€ ์ถ”๊ฐ€ํ•ด๋‹ฌ๋ผ์นผ๊นŒ์š”๐Ÿซ 

Copy link
Member

@9kyo-hwang 9kyo-hwang Nov 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ด์ œ ๊ณง "20366๋ฒˆ - ๊ฐ™์ด ๋ˆˆ์‚ฌ๋žŒ ๋งŒ๋“ค๋ž˜? ๋ฌธ์ œ๊ฐ€ ์žฌ์ฑ„์  ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. (์žฌ์ฑ„์  ์ด์œ : ๋ฐ์ดํ„ฐ ์ถ”๊ฐ€)" ๋ณด๋Š” ๊ฑธ๊นŒ์š” ใ…‹ใ…‹ใ…‹


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)