๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿƒ algorithm/boj

BOJ 3135 - ๋ผ๋””์˜ค

by HandHand 2021. 6. 9.

๋ฌธ์ œ

๋ฐฑ์ค€ ์˜จ๋ผ์ธ ์ €์ง€ - 3135๋ฒˆ

ํ’€์ด ๊ณผ์ •

๋ผ๋””์˜ค์˜ ์„ธ ๊ฐ€์ง€ ๋ฒ„ํŠผ์„ ์ด์šฉํ•ด์„œ ๋ชฉํ‘œ ์ฃผํŒŒ์ˆ˜์— ๋„๋‹ฌํ•˜๋„๋ก ํ•˜๋Š” ์ตœ์†Œ ๋ฒ„ํŠผ ์ž…๋ ฅ ํšŸ์ˆ˜๋ฅผ ๊ตฌํ•˜๋Š” ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค.
์ฃผํŒŒ์ˆ˜์˜ ์ตœ์†Œ ๋ฐ ์ตœ๋Œ€ ์ง€์ ์ด ์„œ๋กœ ์ด์–ด์ ธ์žˆ์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— ๋‹จ์ˆœํ•˜๊ฒŒ ์ฆ๊ฒจ์ฐพ๊ธฐ ๋ชฉ๋ก๋“ค์˜ ์ฃผํŒŒ์ˆ˜๋“ค๊ณผ์˜ ์ฐจ์ด๊ฐ’๊ณผ
A ์—์„œ B ๊นŒ์ง€์˜ ์ฐจ์ด๊ฐ’ ์ค‘ ๊ฐ€์žฅ ์ž‘์€ ๊ฐ’์„ ์ฐพ์œผ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

์ฝ”๋“œ


import sys


def solution():
    min_value = 2e9

    for freq in frequency:
        min_value = min(min_value, abs(freq - B))

    return min(min_value + 1, abs(A - B))


if __name__ == '__main__':
    A, B = list(map(int, sys.stdin.readline().split()))
    N = int(input())
    frequency = [int(input()) for _ in range(N)]

    answer = solution()
    print(answer)
๋ฐ˜์‘ํ˜•

'๐Ÿƒ algorithm > boj' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

BOJ 2644 - ์ดŒ์ˆ˜๊ณ„์‚ฐ  (0) 2021.06.09
BOJ 10026 - ์ ๋ก์ƒ‰์•ฝ  (0) 2021.06.09
BOJ 13410 - ๊ฑฐ๊พธ๋กœ ๊ตฌ๊ตฌ๋‹จ  (0) 2021.06.08
BOJ 2252 - ์ค„ ์„ธ์šฐ๊ธฐ  (0) 2021.06.07
BOJ 2231 - ๋ถ„ํ•ดํ•ฉ  (0) 2021.06.07

๐Ÿ’ฌ ๋Œ“๊ธ€