ํ’€์ด

์ผ๋‹จ input๋ณด๊ณ  ํ•ญ์ƒ ํŒ๋‹จํ•˜๋Š” ๊ฒƒ์ด ์ค‘์š”ํ•˜๋‹ค. ๋ฐฉํ–ฅ๋งŒ ์ž˜ ์žก์œผ๋ฉด ์–ด๋Š์ •๋„ ํ’€ ์ˆ˜ ์žˆ๋‹ค. ์ด์ œ.

์ด๋ถ„ ํƒ์ƒ‰์˜ ํ•ต์‹ฌ์€ ๊ฒฐ๊ตญ ๊ฐ’์„ ์ œ์•ˆํ•˜๊ณ , ๊ทธ ๊ฐ’์ด ๋งž๋Š”์ง€ ํ‹€๋ฆฐ์ง€๋ฅผ ๊ฒ€์ฆํ•˜๋Š” ๋กœ์ง์„ ์ฐพ์„ ์ˆ˜ ์žˆ๋ƒ๋Š” ๊ฒƒ์ด๋‹ค. ์ด ๋ถ€๋ถ„์—์„œ ๊ณ ๋ฏผ์„ ์ข€ ๋งŽ์ด ํ–ˆ๋Š”๋ฐ, ์ž…์ถœ๋ ฅ ์˜ˆ๊ฐ€ ๋„ˆ๋ฌด ๋‚˜๋ฅผ ํ˜ผ๋ž€์Šค๋Ÿฝ๊ฒŒ ํ–ˆ๋‹ค.

๊ทธ๋ƒฅ ์ˆซ์ž๋งŒ ๋”ฑ ๋ณด๊ณ  ์ƒ๊ฐํ•˜๋ฉด, ๊ฐ€์žฅ ์ž‘์€ ์‹œ๊ฐ„์„ ์†Œ์š”ํ•˜๋Š” ์‹ฌ์‚ฌ๊ด€ํ•œํ…Œ ๋ชจ๋“  ์‚ฌ๋žŒ์„ ๋‹ค ๋•Œ๋ ค๋„ฃ์–ด๋ณธ๋‹ค. ๊ทธ๋Ÿฌ๋ฉด ์ œ์•ˆํ•œ ์‹œ๊ฐ„์— ๋Œ€ํ•ด ์ด์‚ฌ๋žŒ์ด ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋Š” ์‚ฌ๋žŒ์˜ ์ƒํ•œ์ด ๋‚˜์˜ค๋Š”๋ฐ, ๊ทธ๊ฑธ ๊ธฐ์ค€์œผ๋กœ ์ƒ๊ฐํ•œ๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด 100๋ถ„๋™์•ˆ ์ฒ˜๋ฆฌํ• ๊ฑฐ์•ผ! ๋ผ๊ณ  ์ œ์•ˆํ–ˆ๋Š”๋ฐ, 7๋ถ„ ๊ฑธ๋ฆฌ๋Š” ์‹ฌ์‚ฌ๊ด€์€ ๊ทธ ์‹œ๊ฐ„๋™์•ˆ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋Š” ์‚ฌ๋žŒ์˜ ์ˆ˜๊ฐ€ 14๋ช…์ธ ๊ฒƒ. ๊ทธ๋Ÿฌ๋ฉด ์ด ์‚ฌ๋žŒ๋ณด๋‹ค ์‹œ๊ฐ„์ด ๋งŽ์ด ๊ฑธ๋ฆฌ๋Š” ์‚ฌ๋žŒ์˜ ๊ฒฝ์šฐ ์ด๊ฒƒ๋ณด๋‹ค ์ ์€ ์‚ฌ๋žŒ์„ ์ฒ˜๋ฆฌํ•˜๊ฒŒ ๋œ๋‹ค.

์ด๋ ‡๊ฒŒ ๊ฐ„๋‹จํ•˜๊ฒŒ ์ƒ๊ฐํ•˜๋ฉด ๋ฌธ์ œ๊ฐ€ ํ’€๋ฆฐ๋‹น.

Code

def solution(n, times):
    
    def isOk(value):
        numOfPerson = 0
        i = 0
        while numOfPerson <= n and i < len(times):
            numOfPerson += (value//times[i])
            i += 1
    
        if numOfPerson >= n: return True
        else: return False
    
    times.sort()
    left, right = 1, times[-1]*n
    while left < right :
        
        mid = (left+right)//2
        if isOk(mid): 
            right = mid
        else: # ์ œ์•ˆํ•œ ๊ฐ’์ด ๋„˜์น˜๋Š” ๊ฒฝ์šฐ 10 > 6
            left = mid+1
    
    return right

Reference