Post

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

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

2469๋ฒˆ: ์น˜ํ‚จ ๋ฐฐ๋‹ฌ


2. ์ฝ”๋“œ

Python3 31120KB 680ms

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""
[1756] ํ”ผ์ž ๊ตฝ๊ธฐ

๐Ÿ’› ๋ฌธ์ œ
์›”๋“œํ”ผ์ž ์›์ฃผ ์ง€์ ์—์„œ N๊ฐœ์˜ ํ”ผ์ž ๋ฐ˜์ฃฝ์„ ์˜ค๋ธ์— ๋„ฃ๊ณ  ๊ตฌ์šฐ๋ ค๊ณ  ํ•œ๋‹ค.
๊ทธ๋Ÿฐ๋ฐ, ์›”๋“œํ”ผ์ž์—์„œ ๋งŒ๋“œ๋Š” ํ”ผ์ž ๋ฐ˜์ฃฝ์€ ์ง€๋ฆ„์ด ์ œ๊ฐ๊ฐ์ด๋‹ค. ๊ทธ๋Ÿฐ๊ฐ€ํ•˜๋ฉด, ์›”๋“œํ”ผ์ž์—์„œ ์‚ฌ์šฉํ•˜๋Š” ์˜ค๋ธ์˜ ๋ชจ์–‘๋„ ๋ชน์‹œ ์˜ค๋ฌ˜ํ•˜๋‹ค.
์ด ์˜ค๋ธ์€ ๊นŠ์€ ๊ด€์ฒ˜๋Ÿผ ์ƒ๊ฒผ๋Š”๋ฐ, ๊ด€์˜ ์ง€๋ฆ„์ด ๊นŠ์ด์— ๋”ฐ๋ผ ๋“ค์ญ‰๋‚ ์ญ‰ํ•˜๊ฒŒ ๋ณ€ํ•œ๋‹ค. ์•„๋ž˜๋Š” ์˜ค๋ธ์˜ ๋‹จ๋ฉด ์˜ˆ์‹œ์ด๋‹ค.

ํ”ผ์ž ๋ฐ˜์ฃฝ์€ ์™„์„ฑ๋˜๋Š” ์ˆœ์„œ๋Œ€๋กœ ์˜ค๋ธ์— ๋“ค์–ด๊ฐ„๋‹ค.
์ด๋ ‡๊ฒŒ N๊ฐœ์˜ ํ”ผ์ž๊ฐ€ ์˜ค๋ธ์— ๋ชจ๋‘ ๋“ค์–ด๊ฐ€๊ณ  ๋‚˜๋ฉด, ๋งจ ์œ„์˜ ํ”ผ์ž๊ฐ€ ์–ผ๋งˆ๋‚˜ ๊นŠ์ด ๋“ค์–ด๊ฐ€ ์žˆ๋Š”์ง€๊ฐ€ ๊ถ๊ธˆํ•˜๋‹ค.
์ด๋ฅผ ์•Œ์•„๋‚ด๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

๐Ÿ’š ์ž…๋ ฅ
์ฒซ์งธ ์ค„์— ์˜ค๋ธ์˜ ๊นŠ์ด D์™€ ํ”ผ์ž ๋ฐ˜์ฃฝ์˜ ๊ฐœ์ˆ˜ N์ด ๊ณต๋ฐฑ์„ ์‚ฌ์ด์— ๋‘๊ณ  ์ฃผ์–ด์ง„๋‹ค. (1 โ‰ค D, N โ‰ค 300,000)
๋‘˜์งธ ์ค„์—๋Š” ์˜ค๋ธ์˜ ์ตœ์ƒ๋‹จ๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜์—ฌ ๊นŠ์ด์— ๋”ฐ๋ฅธ ์˜ค๋ธ์˜ ์ง€๋ฆ„์ด ์ฐจ๋ก€๋Œ€๋กœ ์ฃผ์–ด์ง„๋‹ค.
์…‹์งธ ์ค„์—๋Š” ํ”ผ์ž ๋ฐ˜์ฃฝ์ด ์™„์„ฑ๋˜๋Š” ์ˆœ์„œ๋Œ€๋กœ, ๊ทธ ๊ฐ๊ฐ์˜ ์ง€๋ฆ„์ด ์ฃผ์–ด์ง„๋‹ค.
์˜ค๋ธ์˜ ์ง€๋ฆ„์ด๋‚˜ ํ”ผ์ž ๋ฐ˜์ฃฝ์˜ ์ง€๋ฆ„์€ 10์–ต ์ดํ•˜์˜ ์ž์—ฐ์ˆ˜์ด๋‹ค.

๐Ÿ’™ ์ถœ๋ ฅ
์ฒซ์งธ ์ค„์—, ๋งˆ์ง€๋ง‰ ํ”ผ์ž ๋ฐ˜์ฃฝ์˜ ์œ„์น˜๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค.
์˜ค๋ธ์˜ ์ตœ์ƒ๋‹จ์ด 1์ด๊ณ , ์ตœํ•˜๋‹จ ๊ฐ€์žฅ ๊นŠ์€ ๊ณณ์ด D์ด ๋œ๋‹ค. ๋งŒ์•ฝ ํ”ผ์ž๊ฐ€ ๋ชจ๋‘ ์˜ค๋ธ์— ๋“ค์–ด๊ฐ€์ง€ ์•Š๋Š”๋‹ค๋ฉด, 0์„ ์ถœ๋ ฅํ•œ๋‹ค.
"""

# ์˜ค๋ธ์˜ ๊นŠ์ด D์™€ ํ”ผ์ž ๋ฐ˜์ฃฝ์˜ ๊ฐœ์ˆ˜ N
d, n = map(int, input().split())

# ์˜ค๋ธ์˜ ์ตœ์ƒ๋‹จ๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜์—ฌ ๊นŠ์ด์— ๋”ฐ๋ฅธ ์˜ค๋ธ์˜ ์ง€๋ฆ„
oven = list(map(int, input().split()))

# ํ”ผ์ž ๋ฐ˜์ฃฝ์ด ์™„์„ฑ๋˜๋Š” ์ˆœ์„œ๋Œ€๋กœ, ๊ทธ ๊ฐ๊ฐ์˜ ์ง€๋ฆ„
pizza = list(map(int, input().split()))

# ์žฌ์ •๋ ฌ
for i in range(d - 1):
    if oven[i] < oven[i+1]:
        oven[i+1] = oven[i]

flag = 0

for i in range(d - 1, -1, -1):
    if pizza[flag] > oven[i]:
        continue

    flag += 1
    if flag == n:
        print(i+1)
        break

if flag != n :
    print(0)


3. ํ•ด์„ค

1
2
์˜ค๋ธ ํฌ๊ธฐ๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ํ”ผ์ž๋“ค์„ flag ๋กœ ํ•ฉ์‚ฐํ•œ๋‹ค
ํ”ผ์ž์˜ ์ˆ˜(n) ๊ณผ ๊ฐ™๋‹ค๋ฉด ์˜ค๋ธ์— ๋‹ค ๋„ฃ์€ ๊ฒƒ์ด๊ณ , ๋‹ค๋ฅด๋‹ค๋ฉด -1 ์ด๋‹ค
This post is licensed under CC BY 4.0 by the author.