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

BOJ 1449 - ์ˆ˜๋ฆฌ๊ณต ํ•ญ์Šน

by HandHand 2021. 3. 18.

๋ฌธ์ œ

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

ํ’€์ด ๊ณผ์ •

ํ…Œ์ดํ”„๋ฅผ ๊ฒน์น˜๋Š” ๊ฒƒ์ด ๊ฐ€๋Šฅํ•˜๋ฏ€๋กœ ํƒ์š• ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์„ ์‚ฌ์šฉํ•ด์„œ ์ตœ์†Œ ํ…Œ์ดํ”„ ๊ฐœ์ˆ˜๋ฅผ ๊ตฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

ํ•ญ์ƒ ์ตœ๋Œ€ ๊ธธ์ด์˜ ํ…Œ์ดํ”„๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋ฌผ์ด ์ƒˆ๋Š” ๊ตฌ๊ฐ„์„ ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌํ•˜๋ฉด ๋งจ ์•ž๋ถ€ํ„ฐ ํ…Œ์ดํ”„๋ฅผ ๋ถ™์ด๋ฉด ๋˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.
์ด๋•Œ ๋ฌธ์ œ ์กฐ๊ฑด์— ์ž…๋ ฅ ๊ฐ’์ด ์ •๋ ฌ๋˜์–ด์žˆ๋‹ค๋Š” ์–ธ๊ธ‰์ด ์—†์œผ๋ฏ€๋กœ ๋”ฐ๋กœ ์ •๋ ฌ์‹œ์ผœ์ฃผ๋„๋ก ํ•ฉ๋‹ˆ๋‹ค.

์ฝ”๋“œ


import sys

N, L = list(map(int, sys.stdin.readline().split()))
pipe = list(map(int, sys.stdin.readline().split()))


def solution():
    fixed = [0] * N
    ans = 0

    # ๋ฌผ ์ƒˆ๋Š” ๊ณณ ์ •๋ ฌ
    pipe.sort()

    for spot in range(N):
        if not fixed[spot]:
            ans += 1
            limit = pipe[spot] + L - 1
            for i in range(spot, N):
                if pipe[i] <= limit:
                    fixed[i] = 1
                else:
                    break

    return ans


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

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

BOJ 10819 - ์ฐจ์ด๋ฅผ ์ตœ๋Œ€๋กœ  (0) 2021.03.18
BOJ 15240 - Paint bucket  (0) 2021.03.18
BOJ 2805 - ๋‚˜๋ฌด ์ž๋ฅด๊ธฐ  (0) 2021.03.18
BOJ 1654 - ๋žœ์„  ์ž๋ฅด๊ธฐ  (0) 2021.03.18
BOJ 3184 - ์–‘  (0) 2021.03.18

๐Ÿ’ฌ ๋Œ“๊ธ€