ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

728x90
๋ฐ˜์‘ํ˜•

๋ฌธ์ œ

 

8980๋ฒˆ: ํƒ๋ฐฐ

์ž…๋ ฅ์˜ ์ฒซ ์ค„์€ ๋งˆ์„ ์ˆ˜ N๊ณผ ํŠธ๋Ÿญ์˜ ์šฉ๋Ÿ‰ C๊ฐ€ ๋นˆ์นธ์„ ์‚ฌ์ด์— ๋‘๊ณ  ์ฃผ์–ด์ง„๋‹ค. N์€ 2์ด์ƒ 2,000์ดํ•˜ ์ •์ˆ˜์ด๊ณ , C๋Š” 1์ด์ƒ 10,000์ดํ•˜ ์ •์ˆ˜์ด๋‹ค. ๋‹ค์Œ ์ค„์—, ๋ณด๋‚ด๋Š” ๋ฐ•์Šค ์ •๋ณด์˜ ๊ฐœ์ˆ˜ M์ด ์ฃผ์–ด์ง„๋‹ค. M์€ 1์ด

www.acmicpc.net

 

๋ฌธ์ œ ํ’€์ด

 ์ ‘๊ทผ๋ฒ•์„ ์ƒ๊ฐํ•˜๊ธฐ๊นŒ์ง€ ์‹œ๊ฐ„์ด ๊ฑธ๋ ธ์œผ๋ฉฐ, ๋‹ค์†Œ ์–ด๋ ค์› ๋‹ค. ๋ฌธ์ œ์˜ ํ•ด๋‹ต์€ ๊ฐ ๋งˆ์„ ๋ณ„๋กœ ์ถœ๋ฐœ์ง€ ๋„์ฐฉ์ง€๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์ถœ๋ฐœ ๊ฐ€๋Šฅํ•œ ์–‘์„ ์ง€์†์ ์œผ๋กœ ํ™•์ธํ•ด์•ผ ํ•œ๋‹ค๋Š” ๊ฒƒ์ด๋‹ค.

 

  • ๋งˆ์„ ๋ณ„๋กœ ์‹ค์„ ์ˆ˜ ์žˆ๋Š” ์ตœ๋Œ€ ๋ฐ•์Šค์˜ ์–‘์„ ํŠธ๋Ÿญ์˜ ์šฉ๋Ÿ‰์œผ๋กœ ์ดˆ๊ธฐํ™”ํ•œ๋‹ค.
  • ์ž…๋ ฅ๋œ ๊ฐ’์„ ๋„์ฐฉ์ง€๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์ •๋ ฌํ•œ๋‹ค
  • ์ž…๋ ฅ๋œ ๊ฐ’์„ ์ˆœ์ฐจ์ ์œผ๋กœ ๋Œ๋ฉฐ, ์ถœ๋ฐœ์ง€ ๋„์ฐฉ์ง€์— ์ ์žฌ ๊ฐ€๋Šฅ๋Ÿ‰๊ณผ ๋ฐ•์Šค์˜ ์–‘์„ ๋น„๊ตํ•˜์—ฌ ์ฒ˜๋ฆฌํ•œ๋‹ค.
  • ์ด๋ฅผ ์ˆœ์ฐจ์ ์œผ๋กœ ๋ฐ˜๋ณตํ•˜๋ฉด ์š”๊ตฌํ•˜๋Š” ๋‹ต์„ ์ฐพ์„ ์ˆ˜ ์žˆ๋‹ค.

 

์ฝ”๋“œ

from sys import stdin

if __name__ == "__main__":
    N, C = map(int, stdin.readline().split())
    M = int(stdin.readline())
    info = sorted([list(map(int, stdin.readline().split())) for _ in range(M)], key= lambda x: x[1])

    answer = 0
    village = [C] * N

    for start, end, box in info:
        # list ์ธ๋ฑ์Šค์— ๋งž๊ฒŒ ๋ณ€ํ™˜
        start -= 1
        end -= 1

        # ์ตœ์†Œ ์ ์žฌ๋Ÿ‰ ์„ ํƒ
        load = min(village[start:end])

        if not load:
            continue

        # ์ ์žฌ ๊ฐ€๋Šฅํ•œ ์–‘๋ณด๋‹ค ํฐ ๊ฒฝ์šฐ, ์ ์žฌ ๊ฐ€๋Šฅํ•œ ์–‘๋งŒ
        send = box if box <= load else load

        for idx in range(start, end):
            village[idx] -= send

        answer += send

    print(answer)

 

 

728x90
๋ฐ˜์‘ํ˜•
๋Œ“๊ธ€
๊ธ€ ๋ณด๊ด€ํ•จ
์ตœ๊ทผ์— ์˜ฌ๋ผ์˜จ ๊ธ€
์ตœ๊ทผ์— ๋‹ฌ๋ฆฐ ๋Œ“๊ธ€