Post

๐Ÿน ํ”ผ์ž ๊ตฝ๊ธฐ

1. ๋ฌธ์ œ ๋งํฌ

1756๋ฒˆ: ์‚ฌ๋‹ค๋ฆฌ ํƒ€๊ธฐ


2. ์ฝ”๋“œ

Python3 77796KB 284ms

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
D, N = map(int, input().split())
oven = list(map(int, input().split()))
pizza = list(map(int, input().split()))

dist = 0
# ๋‚ด๋ ค๊ฐˆ ๋•Œ ๋” ํฌ๊ธฐ๊ฐ€ ์ปค์ง€๋Š” ์˜ค๋ธ ์ค„์ด๊ธฐ
for i in range(D-1):
    if oven[i] < oven[i+1]:
        oven[i+1] = oven[i]

idx = D
for p in pizza:
    while idx >= 0:
        idx -= 1
        # ๋“ค์–ด๊ฐˆ ์ˆ˜ ์žˆ๋Š” ํฌ๊ธฐ์˜ ๋„์šฐ
        if p <= oven[idx]:
            break

print(idx + 1)


3. ํ•ด์„ค

์˜ค๋ธ์— ๋ฐ˜์ฃฝ์„ ๋„ฃ์„ ๋•Œ ๋’ค๋กœ ๊ฐˆ์ˆ˜๋ก ์˜ค๋ธ์ด ์ปค์ง„๋‹คํ•ด๋„ ์ž…๊ตฌ์ชฝ์—์„œ ํฌ๊ธฐ๊ฐ€ ์ž‘๋‹ค๋ฉด ํ•ด๋‹น ํฌ๊ธฐ๋ณด๋‹ค ํฐ ๋ฐ˜์ฃฝ์€ ๋“ค์–ด๊ฐˆ ์ˆ˜ ์—†์œผ๋ฏ€๋กœ ์˜ค๋ธ์˜ ํฌ๊ธฐ๋ฅผ ์œ„์ชฝ ํฌ๊ธฐ๋ณด๋‹ค ์•„๋ž˜์ชฝ ํฌ๊ธฐ๋ฅผ ๋” ์ž‘๋„๋ก ๋ณ€๊ฒฝํ•œ๋‹ค.

๋ณ€๊ฒฝ๋œ ์˜ค๋ธ์˜ ๋งจ ์•„๋ž˜๋ถ€ํ„ฐ ๋„์šฐ๋ฅผ ๋„ฃ์–ด์ค€๋‹ค. ์ด๋•Œ ๋„์šฐ๋ฅผ ๋‹ค ๋„ฃ์€ ์‹œ์ ์˜ ์ธ๋ฑ์Šค + 1์ด ๋งˆ์ง€๋ง‰ ๋„์šฐ์˜ ๊นŠ์ด์ด๋‹ค.

This post is licensed under CC BY 4.0 by the author.