๐Ÿค– ์•Œ๊ณ ๋ฆฌ์ฆ˜

โšก๏ธ baekjoon. 1489 ๋Œ€๊ฒฐ [Gold I][python]

ttoance 2023. 6. 29. 23:31

https://www.acmicpc.net/problem/1489

 

1489๋ฒˆ: ๋Œ€๊ฒฐ

์ฒซ์งธ ์ค„์— ํŒ€์— ์†ํ•œ ์‚ฌ๋žŒ์˜ ์ˆ˜ N์ด ์ฃผ์–ด์ง„๋‹ค. ๋‘˜์งธ ์ค„์—๋Š” A1, A2, ..., AN์ด ์ฃผ์–ด์ง€๊ณ , ์…‹์งธ ์ค„์—๋Š” B1, B2, ..., BN์ด ์ฃผ์–ด์ง„๋‹ค.

www.acmicpc.net

 

 

๋‹ค์–‘ํ•œ ํ’€์ด๋ฅผ ์‹œ๋„ํ–ˆ์œผ๋‚˜,  ํ•ด๋ฒ•์„ ์ฐพ์ง€ ๋ชปํ•ด์„œ ๊ฒฐ๊ตญ ๋ธ”๋กœ๊ทธ ๊ธ€์„ ์ฐธ๊ณ ํ–ˆ๋‹ค. 

- ๋™์  ๊ณ„ํš๋ฒ• ํ’€์ด : https://sdev.tistory.com/660

- ์•Œ๊ณ ๋ฆฌ์ฆ˜ ํ’€์ด : https://velog.io/@y7y1h13/%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98%EB%B0%B1%EC%A4%801489-%EB%8C%80%EA%B2%B0python

 

#1489 ๋Œ€๊ฒฐ

์ด๋ฒˆ ๋ฌธ์ œ๋Š” Gold I ๋ฌธ์ œ๋„ค์š”. AํŒ€๊ณผ BํŒ€์ด n๋ช…์˜ ์‚ฌ๋žŒ๋“ค์ด ๊ฐ๊ฐ 1:1 ๋Œ€๊ฒฐํ•ด์„œ ์ŠนํŒจ๋ฅผ ๊ฐ€๋ฆฌ๋Š”๋ฐ, ์ด๊ธฐ๋ฉด 2์ , ๋น„๊ธฐ๋ฉด 1์ , ์ง€๋ฉด 0์ ์„ ๋ฐ›๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ์Šน๋ถ€๋ฅผ ๋ฒŒ์ด๋Š” ๋‘ ์‚ฌ๋žŒ์˜ ๋Šฅ๋ ฅ์น˜๋กœ ์ŠนํŒจ๊ฐ€ ์ขŒ์šฐ๋˜

sdev.tistory.com

 

0% ๋ฐ˜๋ก€

4 
100 1 1 1
100 1 1 1

 

์ฐธ๊ณ ๋กœ, ๋‚ด๊ฐ€ ์ƒ๊ฐํ–ˆ๋˜ ์•Œ๊ณ ๋ฆฌ์ฆ˜์€ ๋‹ค์Œ๊ณผ ๊ฐ™์•˜๋‹ค. 

- A, B ๋ชจ๋‘ ๋‚ด๋ฆผ์ฐจ์ˆœ 

- A ๋ฅผ ๋‚ด๋ฆผ์ฐจ์ˆœ์œผ๋กœ ๋Œ๋ฉด์„œ 

> ์ด๊ธฐ๊ฑฐ๋‚˜ ๋ฌด์Šน๋ถ€๊ฐ€ ๊ฐ€๋Šฅํ•œ ๊ฒฝ์šฐ๋ฅผ ์ฐพ์Œ 

> ์ด๊ธฐ๋Š” ๊ฒฝ์šฐ + 2

> ๋ฌด์Šน๋ถ€์ธ ๊ฒฝ์šฐ, ์ „ํ›„ ๊ฐ’์„ ๋น„๊ตํ•˜๋ฉด์„œ ์ด๊ธฐ๋Š” ๊ฒฝ์šฐ์— ์šฐ์„ ์ˆœ์œ„ ๋‘์–ด ๊ณ„์‚ฐ 

 

์ด๋ ‡๊ฒŒ ํ•ด์„œ ํ•œ ๊ฒฝ์šฐ A : 1 4 7 10 , B : 3 7 8 15 ์—์„œ 10-8, 7-7, 4-3 ํ•ด์„œ 5์ ์ด ์•„๋‹ˆ๋ผ 10-8, 7-3์œผ๋กœ 4์ ์ด ๋‚˜์˜ค๊ฒŒ ๋œ๋‹ค.  

๊ทธ๋ ‡๋‹ค๊ณ  ์šฐ์„ ์ˆœ์œ„๋ฅผ ์•ˆ ๋‘์ž๋‹ˆ A : 1 5 0, B : 1 5 10 ์—์„œ ๊ณ„์† ๋ฌด์Šน๋ถ€๋กœ ๋น ์ง€๊ณ  ..

์ด 2์ผ€์ด์Šค๋ฅผ ๋ชจ๋‘ ๋งŒ์กฑํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ๊ณ ๋ฏผํ•ด๋ณด๋‹ค๊ฐ€, ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด ๋„์ €ํžˆ ์™„์ „ ํƒ์ƒ‰ ๋ง๊ณ ๋Š” ์ƒ๊ฐ์ด ๋‚˜์ง€ ์•Š์•˜๋‹ค.. 

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

A.sort(reverse=True)
B.sort(reverse=True)

bStartIndex = 0
result = 0
for a in A:
    if bStartIndex == len(B):
        break
    
    possibleIndex = 0
    for bIndex in range(bStartIndex, len(B)):
        if (a >= B[bIndex]):
            possibleIndex = bIndex
            break
    
    if a > B[possibleIndex]:
        result += 2
        bStartIndex = possibleIndex + 1
    elif a == B[possibleIndex]:
        # print('> ', possibleIndex, ' > ', bStartIndex)
        if (possibleIndex > 0 and possibleIndex >= bStartIndex and a > B[possibleIndex - 1]):
            result += 2
            bStartIndex = possibleIndex
        else:
            result += 1
            bStartIndex = possibleIndex + 1
            
    # print(a, ' vs ', B[possibleIndex], ' = ', result)
        
print(result)

 

๋ฐ˜์‘ํ˜•