๋‚ด ์ธ์ƒ์—์„œ ๋ฏฟ์„ ๊ฑด ์˜ค์ง ๋‚˜ ์ž์‹ ๋ฟ!

The only one you can truly trust is yourself.

๊ฒŒ์ž„ ํ”„๋กœ๊ทธ๋ž˜๋ฐ/Python ํ”„๋กœ๊ทธ๋ž˜๋ฐ

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ธ์‚ฌ๊ณ ๊ณผ

๐ŸŽฎinspirer9 2023. 2. 14. 00:01
728x90
๋ฐ˜์‘ํ˜•

์ˆœ์—ด, ์กฐํ•ฉ, ์ค‘๋ณต์ˆœ์—ด ๊ณต๋ถ€ํ•ด์„œ ์จ๋จน์–ด๋ณด๋ ค๊ณ  ํ–ˆ๋”๋‹ˆ ์•ˆ๋จ ใ…‹ใ…‹ใ…‹

  • ์‹คํŒจ + ์‹œ๊ฐ„ ์ดˆ๊ณผ์˜ ํ˜ผํ•ฉ... ๋จธ๋ฆฌ๊ฐ€ ๋ฉˆ์ถค ใ…‹
  • ๋‹ค๋ฅธ ๊ฑธ ์จ์•ผ๋˜๋‚˜? ๋” ์†๋„ ๋น ๋ฅธ๊ฑด ์—†๋‚˜? ์ฐพ์•„๋ด„.
  • https://juhee-maeng.tistory.com/91

  • ์•„๋ฌด๊ฒƒ๋„ ์•ˆ๋จน์–ด์„œ ๋จธ๋ฆฌ๊ฐ€ ๋ฉํ•œ๊ฑธ๊นŒ? ๋ฏธ์„ธ๋จผ์ง€ ๋•Œ๋ฌธ์ผ๊นŒ?
  • ํƒˆ๋ฝ์ž ๋ฐฐ์—ด ๋งŒ๋“ค์–ด์„œ ์ ์ˆ˜๋ผ๋ฆฌ ๋น„๊ตํ•˜๊ณ , ํƒˆ๋ฝ์ž์— ์ด์  ๋„ฃ์–ด์„œ ๋น„๊ตํ–ˆ๋Š”๋ฐ ์‹œ๊ฐ„ ์ดˆ๊ณผ๋„ ๋‚˜์˜ค๋ฉด์„œ ์ •๋‹ต๋„ ์•„๋‹Œ ๊ฑธ๋กœ ๋‚˜์˜จ๋‹ค. ์ผ๋‹จ ์‹œ๊ฐ„ ์ดˆ๊ณผ๋ถ€ํ„ฐ ์—†์• ๋ณผ๊นŒ?
from itertools import combinations

def solution(scores):
    ์„์ฐจ = len(scores)
    ํƒˆ๋ฝ์ž = [-99 for i in range(์„์ฐจ)]
    print(ํƒˆ๋ฝ์ž)
    
    for ์ ์ˆ˜ in combinations(range(len(scores)), 2): #ํƒˆ๋ฝํ•œ ๋™๋ฃŒ -1์ 
        if ํƒˆ๋ฝ์ž[์ ์ˆ˜[0]] != -1 and ํƒˆ๋ฝ์ž[์ ์ˆ˜[1]] != -1:
            ๊ทผ๋ฌดํƒœ๋„1, ๋™๋ฃŒ์ ์ˆ˜1 = scores[์ ์ˆ˜[0]][0], scores[์ ์ˆ˜[0]][1]
            ๊ทผ๋ฌดํƒœ๋„2, ๋™๋ฃŒ์ ์ˆ˜2 = scores[์ ์ˆ˜[1]][0], scores[์ ์ˆ˜[1]][1]
            if ๊ทผ๋ฌดํƒœ๋„1 < ๊ทผ๋ฌดํƒœ๋„2 and ๋™๋ฃŒ์ ์ˆ˜1 < ๋™๋ฃŒ์ ์ˆ˜2:
                ํƒˆ๋ฝ์ž[์ ์ˆ˜[0]] = -1
                break
            else:
                ํƒˆ๋ฝ์ž[์ ์ˆ˜[0]] = ๊ทผ๋ฌดํƒœ๋„1 + ๋™๋ฃŒ์ ์ˆ˜1
    
    for i in range(์„์ฐจ):
        if ํƒˆ๋ฝ์ž[i] == -99:
            ํƒˆ๋ฝ์ž[i] = scores[i][0] + scores[i][1]
    
    print(ํƒˆ๋ฝ์ž)
    ์™„ํ˜ธ์˜์ด์  = ํƒˆ๋ฝ์ž.pop(0)
    if ์™„ํ˜ธ์˜์ด์  == -1:
        return ์™„ํ˜ธ์˜์ด์ 
    
    ์„์ฐจ = 0
    for ์ด์  in ํƒˆ๋ฝ์ž:
        if ์™„ํ˜ธ์˜์ด์  < ์ด์ :
            ์„์ฐจ += 1
        print(ํƒˆ๋ฝ์ž, ์™„ํ˜ธ์˜์ด์ , ">", ์ด์ , ์„์ฐจ)
        
    return ์„์ฐจ + 1
    
์ •ํ™•์„ฑ  ํ…Œ์ŠคํŠธ
ํ…Œ์ŠคํŠธ 1 ใ€‰	ํ†ต๊ณผ (0.01ms, 10.4MB)
ํ…Œ์ŠคํŠธ 2 ใ€‰	ํ†ต๊ณผ (0.01ms, 10.5MB)
ํ…Œ์ŠคํŠธ 3 ใ€‰	ํ†ต๊ณผ (0.01ms, 10.5MB)
ํ…Œ์ŠคํŠธ 4 ใ€‰	ํ†ต๊ณผ (0.01ms, 10.5MB)
ํ…Œ์ŠคํŠธ 5 ใ€‰	ํ†ต๊ณผ (0.02ms, 10.3MB)
ํ…Œ์ŠคํŠธ 6 ใ€‰	ํ†ต๊ณผ (0.01ms, 10.4MB)
ํ…Œ์ŠคํŠธ 7 ใ€‰	ํ†ต๊ณผ (0.02ms, 10.4MB)
ํ…Œ์ŠคํŠธ 8 ใ€‰	์‹คํŒจ (0.04ms, 10.6MB)
ํ…Œ์ŠคํŠธ 9 ใ€‰	ํ†ต๊ณผ (0.04ms, 10.6MB)
ํ…Œ์ŠคํŠธ 10 ใ€‰	์‹คํŒจ (0.09ms, 10.4MB)
ํ…Œ์ŠคํŠธ 11 ใ€‰	์‹คํŒจ (0.28ms, 10.5MB)
ํ…Œ์ŠคํŠธ 12 ใ€‰	ํ†ต๊ณผ (0.32ms, 10.4MB)
ํ…Œ์ŠคํŠธ 13 ใ€‰	ํ†ต๊ณผ (0.43ms, 10.4MB)
ํ…Œ์ŠคํŠธ 14 ใ€‰	์‹คํŒจ (0.59ms, 10.6MB)
ํ…Œ์ŠคํŠธ 15 ใ€‰	ํ†ต๊ณผ (1.77ms, 11.1MB)
ํ…Œ์ŠคํŠธ 16 ใ€‰	์‹คํŒจ (3.06ms, 11MB)
ํ…Œ์ŠคํŠธ 17 ใ€‰	ํ†ต๊ณผ (5.96ms, 12MB)
ํ…Œ์ŠคํŠธ 18 ใ€‰	ํ†ต๊ณผ (6.04ms, 12MB)
ํ…Œ์ŠคํŠธ 19 ใ€‰	ํ†ต๊ณผ (12.82ms, 19.8MB)
ํ…Œ์ŠคํŠธ 20 ใ€‰	ํ†ต๊ณผ (15.75ms, 19.7MB)
ํ…Œ์ŠคํŠธ 21 ใ€‰	์‹คํŒจ (์‹œ๊ฐ„ ์ดˆ๊ณผ)
ํ…Œ์ŠคํŠธ 22 ใ€‰	์‹คํŒจ (61.33ms, 29.3MB)
ํ…Œ์ŠคํŠธ 23 ใ€‰	ํ†ต๊ณผ (52.49ms, 29.5MB)
ํ…Œ์ŠคํŠธ 24 ใ€‰	์‹คํŒจ (์‹œ๊ฐ„ ์ดˆ๊ณผ)
ํ…Œ์ŠคํŠธ 25 ใ€‰	์‹คํŒจ (์‹œ๊ฐ„ ์ดˆ๊ณผ)
  • ์—ด์‹ฌํžˆ ์งฑ๋Œ์„ ๊ตด๋ ค๋ณด๋‹ˆ, ์–ด์ฐจํ”ผ ์ด์ ์ด ๋†’์€ ์• ๋“ค๋งŒ ๊ตฌํ•˜๋ฉด๋˜๋‹ˆ๊นŒ ์ด์ ์ด ๋‚ฎ์€ ์• ๋“ค์ด ํƒˆ๋ฝ์ธ์ง€ ์•„๋‹Œ์ง€ ๊ณ„์‚ฐํ•  ํ•„์š”๊ฐ€ ์—†์—ˆ๋‹ค. ์ด์ ์ด ๋†’์€ ์• ๋“ค๋งŒ ์†ŒํŒ…ํ•ด์„œ ๋‹ค์‹œ ํ•ด๋ณด์ž๊ตฌ...
  • ํ†ต๊ณผ๋Š” ๋˜๋Š”๋ฐ ์‹œ๊ฐ„ ์ดˆ๊ณผ์—์„œ ๊ฑธ๋ฆฌ๋Š”๊ตฌ๋‚˜... ํ•œ๊ธ€ ๋ณ€์ˆ˜๋กœ ํ•ด์„œ ๊ทธ๋Ÿฐ๊ฐ€ ใ…‹
from itertools import combinations

def solution(scores):
    ์™„ํ˜ธ์˜ํƒœ๋„์ ์ˆ˜, ์™„ํ˜ธ์˜ํ‰๊ฐ€์ ์ˆ˜ = scores.pop(0)
    ์™„ํ˜ธ์˜์ด์  = ์™„ํ˜ธ์˜ํƒœ๋„์ ์ˆ˜ + ์™„ํ˜ธ์˜ํ‰๊ฐ€์ ์ˆ˜
    
    scores.sort(key=lambda x:x[0]+x[1]) #์ด์  ์ˆœ ์ •๋ ฌ
    scores = [x for x in scores if x[0]+x[1] > ์™„ํ˜ธ์˜์ด์ ] #์™„ํ˜ธ์˜ ์ด์ ๋ณด๋‹ค ๋‚ฎ์€ ์ ์ˆ˜ ์ œ๊ฑฐ
    len_scores = len(scores)
    answer = len_scores + 1
    
    #print(answer)
    for i in range(len_scores):
        ํƒœ๋„์ ์ˆ˜1, ํ‰๊ฐ€์ ์ˆ˜1 = scores[i][0], scores[i][1]
        #print("์™„ํ˜ธ์˜ํƒœ๋„์ ์ˆ˜, ์™„ํ˜ธ์˜ํ‰๊ฐ€์ ์ˆ˜k, ํƒœ๋„์ ์ˆ˜1, ํ‰๊ฐ€์ ์ˆ˜1:", ์™„ํ˜ธ์˜ํƒœ๋„์ ์ˆ˜, ์™„ํ˜ธ์˜ํ‰๊ฐ€์ ์ˆ˜, ํƒœ๋„์ ์ˆ˜1, ํ‰๊ฐ€์ ์ˆ˜1)
        if ์™„ํ˜ธ์˜ํƒœ๋„์ ์ˆ˜ < ํƒœ๋„์ ์ˆ˜1 and ์™„ํ˜ธ์˜ํ‰๊ฐ€์ ์ˆ˜ < ํ‰๊ฐ€์ ์ˆ˜1:
            return -1
        
        for j in range(i,len_scores):
            ํƒœ๋„์ ์ˆ˜2, ํ‰๊ฐ€์ ์ˆ˜2 = scores[j][0], scores[j][1]
            #print("ํƒœ๋„์ ์ˆ˜1, ํ‰๊ฐ€์ ์ˆ˜1, ํƒœ๋„์ ์ˆ˜2, ํ‰๊ฐ€์ ์ˆ˜2:", ํƒœ๋„์ ์ˆ˜1, ํ‰๊ฐ€์ ์ˆ˜1, ํƒœ๋„์ ์ˆ˜2, ํ‰๊ฐ€์ ์ˆ˜2)
            if ํƒœ๋„์ ์ˆ˜1 < ํƒœ๋„์ ์ˆ˜2 and ํ‰๊ฐ€์ ์ˆ˜1 < ํ‰๊ฐ€์ ์ˆ˜2:
                #print("๋“ฑ์ˆ˜ ์˜ค๋ฆ„")
                answer -= 1
                break
        
    return answer
    
์ •ํ™•์„ฑ  ํ…Œ์ŠคํŠธ
ํ…Œ์ŠคํŠธ 1 ใ€‰	ํ†ต๊ณผ (0.01ms, 10.3MB)
ํ…Œ์ŠคํŠธ 2 ใ€‰	ํ†ต๊ณผ (0.01ms, 10.3MB)
ํ…Œ์ŠคํŠธ 3 ใ€‰	ํ†ต๊ณผ (0.01ms, 10.3MB)
ํ…Œ์ŠคํŠธ 4 ใ€‰	ํ†ต๊ณผ (0.01ms, 10.4MB)
ํ…Œ์ŠคํŠธ 5 ใ€‰	ํ†ต๊ณผ (0.01ms, 10.3MB)
ํ…Œ์ŠคํŠธ 6 ใ€‰	ํ†ต๊ณผ (0.01ms, 10.4MB)
ํ…Œ์ŠคํŠธ 7 ใ€‰	ํ†ต๊ณผ (0.01ms, 10.3MB)
ํ…Œ์ŠคํŠธ 8 ใ€‰	ํ†ต๊ณผ (0.02ms, 10.4MB)
ํ…Œ์ŠคํŠธ 9 ใ€‰	ํ†ต๊ณผ (0.05ms, 10.6MB)
ํ…Œ์ŠคํŠธ 10 ใ€‰	ํ†ต๊ณผ (0.04ms, 10.3MB)
ํ…Œ์ŠคํŠธ 11 ใ€‰	ํ†ต๊ณผ (1.78ms, 10.3MB)
ํ…Œ์ŠคํŠธ 12 ใ€‰	ํ†ต๊ณผ (0.25ms, 10.4MB)
ํ…Œ์ŠคํŠธ 13 ใ€‰	ํ†ต๊ณผ (0.37ms, 10.3MB)
ํ…Œ์ŠคํŠธ 14 ใ€‰	ํ†ต๊ณผ (0.51ms, 10.4MB)
ํ…Œ์ŠคํŠธ 15 ใ€‰	ํ†ต๊ณผ (1.77ms, 10.8MB)
ํ…Œ์ŠคํŠธ 16 ใ€‰	ํ†ต๊ณผ (5.97ms, 11MB)
ํ…Œ์ŠคํŠธ 17 ใ€‰	ํ†ต๊ณผ (5.47ms, 11.8MB)
ํ…Œ์ŠคํŠธ 18 ใ€‰	ํ†ต๊ณผ (3.59ms, 12.1MB)
ํ…Œ์ŠคํŠธ 19 ใ€‰	ํ†ต๊ณผ (33.63ms, 19.7MB)
ํ…Œ์ŠคํŠธ 20 ใ€‰	ํ†ต๊ณผ (22.31ms, 19.6MB)
ํ…Œ์ŠคํŠธ 21 ใ€‰	ํ†ต๊ณผ (31.54ms, 19.3MB)
ํ…Œ์ŠคํŠธ 22 ใ€‰	ํ†ต๊ณผ (527.02ms, 29.7MB)
ํ…Œ์ŠคํŠธ 23 ใ€‰	ํ†ต๊ณผ (418.40ms, 29.4MB)
ํ…Œ์ŠคํŠธ 24 ใ€‰	์‹คํŒจ (์‹œ๊ฐ„ ์ดˆ๊ณผ)
ํ…Œ์ŠคํŠธ 25 ใ€‰	์‹คํŒจ (์‹œ๊ฐ„ ์ดˆ๊ณผ)
  • ํฐ ๊ฐ’๋ถ€ํ„ฐ ๊ฑฐ๊พธ๋กœ ๋น„๊ตํ•˜๋ฉด ์ข€ ๋” ๋นจ๋ผ์ง€์ง€ ์•Š์„๊นŒ?
  • ์•„๋‹ˆ๋„ค.. ์–ด๋–ค ์œ„์น˜์— ๋ญ๊ฐ€ ์žˆ์„์ง€ ๋ชจ๋ฅด๋‹ˆ๊นŒ ์•ˆ๋˜๋‚˜?
from itertools import combinations

def solution(scores):
    ์™„ํ˜ธ์˜ํƒœ๋„์ ์ˆ˜, ์™„ํ˜ธ์˜ํ‰๊ฐ€์ ์ˆ˜ = scores.pop(0)
    ์™„ํ˜ธ์˜์ด์  = ์™„ํ˜ธ์˜ํƒœ๋„์ ์ˆ˜ + ์™„ํ˜ธ์˜ํ‰๊ฐ€์ ์ˆ˜
    
    scores.sort(key=lambda x:x[0]+x[1]) #์ด์  ์ˆœ ์ •๋ ฌ
    scores = [x for x in scores if x[0]+x[1] > ์™„ํ˜ธ์˜์ด์ ] #์™„ํ˜ธ์˜ ์ด์ ๋ณด๋‹ค ๋‚ฎ์€ ์ ์ˆ˜ ์ œ๊ฑฐ
    len_scores = len(scores)
    answer = len_scores + 1
    
    #print(answer)
    for i in range(len_scores):
        ํƒœ๋„์ ์ˆ˜1, ํ‰๊ฐ€์ ์ˆ˜1 = scores[i][0], scores[i][1]
        #print("์™„ํ˜ธ์˜ํƒœ๋„์ ์ˆ˜, ์™„ํ˜ธ์˜ํ‰๊ฐ€์ ์ˆ˜k, ํƒœ๋„์ ์ˆ˜1, ํ‰๊ฐ€์ ์ˆ˜1:", ์™„ํ˜ธ์˜ํƒœ๋„์ ์ˆ˜, ์™„ํ˜ธ์˜ํ‰๊ฐ€์ ์ˆ˜, ํƒœ๋„์ ์ˆ˜1, ํ‰๊ฐ€์ ์ˆ˜1)
        if ์™„ํ˜ธ์˜ํƒœ๋„์ ์ˆ˜ < ํƒœ๋„์ ์ˆ˜1 and ์™„ํ˜ธ์˜ํ‰๊ฐ€์ ์ˆ˜ < ํ‰๊ฐ€์ ์ˆ˜1:
            return -1
        
        for j in reversed(range(i,len_scores)):
            ํƒœ๋„์ ์ˆ˜2, ํ‰๊ฐ€์ ์ˆ˜2 = scores[j][0], scores[j][1]
            #print("ํƒœ๋„์ ์ˆ˜1, ํ‰๊ฐ€์ ์ˆ˜1, ํƒœ๋„์ ์ˆ˜2, ํ‰๊ฐ€์ ์ˆ˜2:", ํƒœ๋„์ ์ˆ˜1, ํ‰๊ฐ€์ ์ˆ˜1, ํƒœ๋„์ ์ˆ˜2, ํ‰๊ฐ€์ ์ˆ˜2)
            if ํƒœ๋„์ ์ˆ˜1 < ํƒœ๋„์ ์ˆ˜2 and ํ‰๊ฐ€์ ์ˆ˜1 < ํ‰๊ฐ€์ ์ˆ˜2:
                #print("๋“ฑ์ˆ˜ ์˜ค๋ฆ„")
                answer -= 1
                break
        
    return answer
    
์ •ํ™•์„ฑ  ํ…Œ์ŠคํŠธ
ํ…Œ์ŠคํŠธ 1 ใ€‰	ํ†ต๊ณผ (0.01ms, 10.3MB)
ํ…Œ์ŠคํŠธ 2 ใ€‰	ํ†ต๊ณผ (0.01ms, 10.4MB)
ํ…Œ์ŠคํŠธ 3 ใ€‰	ํ†ต๊ณผ (0.02ms, 10.4MB)
ํ…Œ์ŠคํŠธ 4 ใ€‰	ํ†ต๊ณผ (0.01ms, 10.3MB)
ํ…Œ์ŠคํŠธ 5 ใ€‰	ํ†ต๊ณผ (0.01ms, 10.3MB)
ํ…Œ์ŠคํŠธ 6 ใ€‰	ํ†ต๊ณผ (0.02ms, 10.3MB)
ํ…Œ์ŠคํŠธ 7 ใ€‰	ํ†ต๊ณผ (0.02ms, 10.6MB)
ํ…Œ์ŠคํŠธ 8 ใ€‰	ํ†ต๊ณผ (0.02ms, 10.4MB)
ํ…Œ์ŠคํŠธ 9 ใ€‰	ํ†ต๊ณผ (0.06ms, 10.5MB)
ํ…Œ์ŠคํŠธ 10 ใ€‰	ํ†ต๊ณผ (0.06ms, 10.4MB)
ํ…Œ์ŠคํŠธ 11 ใ€‰	ํ†ต๊ณผ (0.60ms, 10.4MB)
ํ…Œ์ŠคํŠธ 12 ใ€‰	ํ†ต๊ณผ (0.25ms, 10.6MB)
ํ…Œ์ŠคํŠธ 13 ใ€‰	ํ†ต๊ณผ (0.25ms, 10.4MB)
ํ…Œ์ŠคํŠธ 14 ใ€‰	ํ†ต๊ณผ (0.36ms, 10.4MB)
ํ…Œ์ŠคํŠธ 15 ใ€‰	ํ†ต๊ณผ (1.59ms, 10.9MB)
ํ…Œ์ŠคํŠธ 16 ใ€‰	ํ†ต๊ณผ (2.45ms, 11.3MB)
ํ…Œ์ŠคํŠธ 17 ใ€‰	ํ†ต๊ณผ (5.93ms, 11.8MB)
ํ…Œ์ŠคํŠธ 18 ใ€‰	ํ†ต๊ณผ (4.31ms, 12MB)
ํ…Œ์ŠคํŠธ 19 ใ€‰	ํ†ต๊ณผ (30.54ms, 19.8MB)
ํ…Œ์ŠคํŠธ 20 ใ€‰	ํ†ต๊ณผ (32.83ms, 19.7MB)
ํ…Œ์ŠคํŠธ 21 ใ€‰	ํ†ต๊ณผ (20.23ms, 19.2MB)
ํ…Œ์ŠคํŠธ 22 ใ€‰	ํ†ต๊ณผ (170.26ms, 29.8MB)
ํ…Œ์ŠคํŠธ 23 ใ€‰	ํ†ต๊ณผ (96.49ms, 29.2MB)
ํ…Œ์ŠคํŠธ 24 ใ€‰	์‹คํŒจ (์‹œ๊ฐ„ ์ดˆ๊ณผ)
ํ…Œ์ŠคํŠธ 25 ใ€‰	์‹คํŒจ (์‹œ๊ฐ„ ์ดˆ๊ณผ)
  • ํ•จ์ • ์ฐพ์•˜๋„ค? ์™„ํ˜ธ๋งŒ ๋“ค์–ด์žˆ๋Š” ๋ฐฐ์—ด์„ ์ฃผ๋Š”๊ตฌ๋‚˜?
  • ๊ทผ๋ฐ ๊ทธ๋Ÿฌ๋ฉด ๋™๋ฃŒ ํ‰๊ฐ€ ์ ์ˆ˜๋ฅผ ์–ด๋–ป๊ฒŒ ๋ฐ›๋ƒ? ๋™๋ฃŒ๊ฐ€ ์—†๋Š”๋ฐ? ์“ฐ๋ ˆ๊ธฐ ํ•จ์ •์ด๋„ค ใ…‹ใ…‹ใ…‹
  • ํ•˜์ง€๋งŒ ํ†ต๊ณผ ๋ชปํ•จ...?
from itertools import combinations

def solution(scores):
    ์™„ํ˜ธ์˜ํƒœ๋„์ ์ˆ˜, ์™„ํ˜ธ์˜ํ‰๊ฐ€์ ์ˆ˜ = scores.pop(0)
    ์™„ํ˜ธ์˜์ด์  = ์™„ํ˜ธ์˜ํƒœ๋„์ ์ˆ˜ + ์™„ํ˜ธ์˜ํ‰๊ฐ€์ ์ˆ˜
    
    scores = [x for x in scores if x[0]+x[1] > ์™„ํ˜ธ์˜์ด์ ] #์™„ํ˜ธ์˜ ์ด์ ๋ณด๋‹ค ๋‚ฎ์€ ์ ์ˆ˜ ์ œ๊ฑฐ
    scores.sort(key=lambda x:x[0]+x[1], reverse=True) #ํฐ ๊ฐ’๋ถ€ํ„ฐ
    
    if len(scores) == 0: #ํ•จ์ •์ด ์ด๊ฑฐ์˜€์–ด? ใ…ก.ใ…ก;
        return 1
    
    for i in range(len(scores)):
        ํƒœ๋„์ ์ˆ˜1, ํ‰๊ฐ€์ ์ˆ˜1 = scores[i][0], scores[i][1]
        if ์™„ํ˜ธ์˜ํƒœ๋„์ ์ˆ˜ < ํƒœ๋„์ ์ˆ˜1 and ์™„ํ˜ธ์˜ํ‰๊ฐ€์ ์ˆ˜ < ํ‰๊ฐ€์ ์ˆ˜1:
            return -1
    
    i = 0
    while i < len(scores)-1:
        for j in reversed(range(len(scores))):
            ํƒœ๋„์ ์ˆ˜1, ํ‰๊ฐ€์ ์ˆ˜1 = scores[i][0], scores[i][1]
            ํƒœ๋„์ ์ˆ˜2, ํ‰๊ฐ€์ ์ˆ˜2 = scores[j][0], scores[j][1]
            ์ด์ 1 = ํƒœ๋„์ ์ˆ˜1 + ํ‰๊ฐ€์ ์ˆ˜1
            ์ด์ 2 = ํƒœ๋„์ ์ˆ˜2 + ํ‰๊ฐ€์ ์ˆ˜2
            #print(์ด์ 1, ํƒœ๋„์ ์ˆ˜1, ํ‰๊ฐ€์ ์ˆ˜1, ์ด์ 2, ํƒœ๋„์ ์ˆ˜2, ํ‰๊ฐ€์ ์ˆ˜2)
            if ์ด์ 1 > ์ด์ 2 + 1:
                if ํƒœ๋„์ ์ˆ˜1 > ํƒœ๋„์ ์ˆ˜2 and ํ‰๊ฐ€์ ์ˆ˜1 > ํ‰๊ฐ€์ ์ˆ˜2:
                    scores.pop(j)
            #print(scores)
        i += 1
    
    return len(scores) + 1
    
์ •ํ™•์„ฑ  ํ…Œ์ŠคํŠธ
ํ…Œ์ŠคํŠธ 1 ใ€‰	ํ†ต๊ณผ (0.01ms, 10.4MB)
ํ…Œ์ŠคํŠธ 2 ใ€‰	ํ†ต๊ณผ (0.00ms, 10.4MB)
ํ…Œ์ŠคํŠธ 3 ใ€‰	ํ†ต๊ณผ (0.02ms, 10.4MB)
ํ…Œ์ŠคํŠธ 4 ใ€‰	ํ†ต๊ณผ (0.02ms, 10.5MB)
ํ…Œ์ŠคํŠธ 5 ใ€‰	ํ†ต๊ณผ (0.00ms, 10.6MB)
ํ…Œ์ŠคํŠธ 6 ใ€‰	ํ†ต๊ณผ (0.01ms, 10.6MB)
ํ…Œ์ŠคํŠธ 7 ใ€‰	ํ†ต๊ณผ (0.01ms, 10.4MB)
ํ…Œ์ŠคํŠธ 8 ใ€‰	ํ†ต๊ณผ (0.01ms, 10.4MB)
ํ…Œ์ŠคํŠธ 9 ใ€‰	ํ†ต๊ณผ (0.02ms, 10.4MB)
ํ…Œ์ŠคํŠธ 10 ใ€‰	ํ†ต๊ณผ (0.02ms, 10.4MB)
ํ…Œ์ŠคํŠธ 11 ใ€‰	ํ†ต๊ณผ (0.34ms, 10.4MB)
ํ…Œ์ŠคํŠธ 12 ใ€‰	ํ†ต๊ณผ (0.07ms, 10.3MB)
ํ…Œ์ŠคํŠธ 13 ใ€‰	ํ†ต๊ณผ (0.08ms, 10.2MB)
ํ…Œ์ŠคํŠธ 14 ใ€‰	ํ†ต๊ณผ (0.31ms, 10.5MB)
ํ…Œ์ŠคํŠธ 15 ใ€‰	ํ†ต๊ณผ (0.36ms, 10.8MB)
ํ…Œ์ŠคํŠธ 16 ใ€‰	ํ†ต๊ณผ (1.08ms, 10.7MB)
ํ…Œ์ŠคํŠธ 17 ใ€‰	ํ†ต๊ณผ (0.69ms, 11.7MB)
ํ…Œ์ŠคํŠธ 18 ใ€‰	ํ†ต๊ณผ (1.39ms, 11.4MB)
ํ…Œ์ŠคํŠธ 19 ใ€‰	ํ†ต๊ณผ (3.71ms, 17.5MB)
ํ…Œ์ŠคํŠธ 20 ใ€‰	ํ†ต๊ณผ (3.48ms, 17.8MB)
ํ…Œ์ŠคํŠธ 21 ใ€‰	ํ†ต๊ณผ (5.89ms, 18.8MB)
ํ…Œ์ŠคํŠธ 22 ใ€‰	ํ†ต๊ณผ (22.79ms, 25.7MB)
ํ…Œ์ŠคํŠธ 23 ใ€‰	ํ†ต๊ณผ (12.27ms, 25.7MB)
ํ…Œ์ŠคํŠธ 24 ใ€‰	์‹คํŒจ (์‹œ๊ฐ„ ์ดˆ๊ณผ)
ํ…Œ์ŠคํŠธ 25 ใ€‰	์‹คํŒจ (์‹œ๊ฐ„ ์ดˆ๊ณผ)
  • ์ด์ œ ๋‚จ์€ ๊ฑด ๋” ๋น ๋ฅธ ๋ฐ์ดํ„ฐ ๊ตฌ์กฐ๋กœ ๋ฐ”๊ฟ”๋ณด๋Š” ๊ฑฐ? heapq์˜€๋‚˜... ๊ทธ๊ฒƒ๋„ ์•ž๋’ค๋กœ๋งŒ ๋บ„ ์ˆ˜ ์žˆ๊ณ ...
  • ์ž๋ฃŒ ๊ตฌ์กฐ ๋ฐ”๊ฟ”๋„ ์†Œ์šฉ์ด ์—†๋‹ค. ๊ทธ๋Ÿฌ๋ฉด ๋ญ๋‹ค? ์ˆ˜ํ•™ ์ˆ™์ œ๋‹ค. ์ˆ˜ํ•™ ใ…ก.ใ…ก;
def solution(scores):
    ์™„ํ˜ธ์˜ํƒœ๋„์ ์ˆ˜, ์™„ํ˜ธ์˜ํ‰๊ฐ€์ ์ˆ˜ = scores.pop(0)
    ์™„ํ˜ธ์˜์ด์  = ์™„ํ˜ธ์˜ํƒœ๋„์ ์ˆ˜ + ์™„ํ˜ธ์˜ํ‰๊ฐ€์ ์ˆ˜
    
    scores = [x for x in scores if sum(x) > ์™„ํ˜ธ์˜์ด์ ] #์™„ํ˜ธ์˜ ์ด์ ๋ณด๋‹ค ๋‚ฎ์€ ์ ์ˆ˜ ์ œ๊ฑฐ
    scores.sort(key=lambda x:sum(x), reverse=True) #ํฐ ๊ฐ’๋ถ€ํ„ฐ
    
    if len(scores) == 0: #ํ•จ์ •์ด ์ด๊ฑฐ์˜€์–ด? ใ…ก.ใ…ก;
        return 1
    
    for i in scores:
        if ์™„ํ˜ธ์˜ํƒœ๋„์ ์ˆ˜ < i[0] and ์™„ํ˜ธ์˜ํ‰๊ฐ€์ ์ˆ˜ < i[1]:
            return -1
        
    i = 0
    while i < len(scores)-1:
        ํƒœ๋„์ ์ˆ˜1, ํ‰๊ฐ€์ ์ˆ˜1 = scores[i][0], scores[i][1]
        j = i + 1
        while j < len(scores):
            ํƒœ๋„์ ์ˆ˜2, ํ‰๊ฐ€์ ์ˆ˜2 = scores[j][0], scores[j][1]
            if ํƒœ๋„์ ์ˆ˜1 > ํƒœ๋„์ ์ˆ˜2 and ํ‰๊ฐ€์ ์ˆ˜1 > ํ‰๊ฐ€์ ์ˆ˜2:
                scores.pop(j)
            else:
                j += 1
        i += 1
    
    return len(scores) + 1
    
์ •ํ™•์„ฑ  ํ…Œ์ŠคํŠธ
ํ…Œ์ŠคํŠธ 1 ใ€‰	ํ†ต๊ณผ (0.01ms, 10.2MB)
ํ…Œ์ŠคํŠธ 2 ใ€‰	ํ†ต๊ณผ (0.01ms, 10.5MB)
ํ…Œ์ŠคํŠธ 3 ใ€‰	ํ†ต๊ณผ (0.01ms, 10.6MB)
ํ…Œ์ŠคํŠธ 4 ใ€‰	ํ†ต๊ณผ (0.02ms, 10.4MB)
ํ…Œ์ŠคํŠธ 5 ใ€‰	ํ†ต๊ณผ (0.01ms, 10.4MB)
ํ…Œ์ŠคํŠธ 6 ใ€‰	ํ†ต๊ณผ (0.01ms, 10.5MB)
ํ…Œ์ŠคํŠธ 7 ใ€‰	ํ†ต๊ณผ (0.01ms, 10.5MB)
ํ…Œ์ŠคํŠธ 8 ใ€‰	ํ†ต๊ณผ (0.02ms, 10.4MB)
ํ…Œ์ŠคํŠธ 9 ใ€‰	ํ†ต๊ณผ (0.02ms, 10.2MB)
ํ…Œ์ŠคํŠธ 10 ใ€‰	ํ†ต๊ณผ (0.02ms, 10.5MB)
ํ…Œ์ŠคํŠธ 11 ใ€‰	ํ†ต๊ณผ (0.22ms, 10.4MB)
ํ…Œ์ŠคํŠธ 12 ใ€‰	ํ†ต๊ณผ (0.10ms, 10.4MB)
ํ…Œ์ŠคํŠธ 13 ใ€‰	ํ†ต๊ณผ (0.11ms, 10.5MB)
ํ…Œ์ŠคํŠธ 14 ใ€‰	ํ†ต๊ณผ (0.18ms, 10.4MB)
ํ…Œ์ŠคํŠธ 15 ใ€‰	ํ†ต๊ณผ (0.49ms, 10.9MB)
ํ…Œ์ŠคํŠธ 16 ใ€‰	ํ†ต๊ณผ (1.03ms, 10.7MB)
ํ…Œ์ŠคํŠธ 17 ใ€‰	ํ†ต๊ณผ (2.11ms, 11.6MB)
ํ…Œ์ŠคํŠธ 18 ใ€‰	ํ†ต๊ณผ (2.10ms, 11.7MB)
ํ…Œ์ŠคํŠธ 19 ใ€‰	ํ†ต๊ณผ (5.11ms, 17.7MB)
ํ…Œ์ŠคํŠธ 20 ใ€‰	ํ†ต๊ณผ (4.98ms, 17.9MB)
ํ…Œ์ŠคํŠธ 21 ใ€‰	ํ†ต๊ณผ (8.67ms, 18.9MB)
ํ…Œ์ŠคํŠธ 22 ใ€‰	ํ†ต๊ณผ (47.53ms, 25.8MB)
ํ…Œ์ŠคํŠธ 23 ใ€‰	ํ†ต๊ณผ (19.08ms, 25.7MB)
ํ…Œ์ŠคํŠธ 24 ใ€‰	์‹คํŒจ (์‹œ๊ฐ„ ์ดˆ๊ณผ)
ํ…Œ์ŠคํŠธ 25 ใ€‰	์‹คํŒจ (์‹œ๊ฐ„ ์ดˆ๊ณผ)
  • ์•”ํŠผ ๊ทธ๋ž˜์„œ ๋‘ ์ ์ˆ˜ A,B๋กœ (A+B, A-B) ์ขŒ๋ฃŒ๋กœ ์ ์„ ์ฐ์–ด๋ณด๋‹ˆ๊นŒ ์ด๋Ÿฐ ๊ทœ์น™์ด ๋‚˜์˜จ๋‹ค.
  • (A-B)ํ•œ ๊ฐ’์—์„œ (A+B)ํ•œ ์ตœ๋Œ€๊ฐ’์„ ๋„ฃ๊ณ , ์ด๊ฑฐ๋ณด๋‹ค ์ž‘์œผ๋ฉด ํƒˆ๋ฝ ์‹œ์ผœ์„œ ์ธ์„ผํ‹ฐ๋ธŒ๋ฅผ ์•ˆ์ฃผ๋ฉด ๋œ๋‹ค.
  • (A-B)ํ‚ค๋กœ ๋”•์…”๋„ˆ๋ฆฌ๋ฅผ ๋งŒ๋“ค์–ด์„œ (A+B)๋ฅผ ๊ฐ’์œผ๋กœ ์“ฐ๋ฉด ๋œ๋‹ค. ํฐ๊ฑฐ๋ถ€ํ„ฐ ํ• ๊ฑฐ๋‹ˆ๊นŒ ๊ฐฑ์‹ ํ•  ํ•„์š”๋„ ์—†๊ณ ...
  • ์•„๋‹ˆ์•ผ. ๋Œ€๊ฐ์„ ์œผ๋กœ๋„ ์ฒดํฌํ•ด์•ผ๋˜๊ณ , ๊ฒฐ๊ตญ ๋‹ค ๋’ค์ ธ์•ผ ํ•œ๋‹ค.

  • ๋ญ”๊ฐ€ ๋‹ค๋ฅธ ๋ฐฉ๋ฒ• ์—†๋‚˜?
    • ์˜ˆ๋ฅผ ๋“ค๋ฉด ํƒœ๋„ ์ ์ˆ˜๊ฐ€ ์„œ๋กœ ๊ฐ™์œผ๋ฉด... ํƒˆ๋ฝ์ด ์•„๋‹ˆ๋‹ˆ๊นŒ ๋„˜์–ด๊ฐ€๋ฉด ๋œ๋‹ค.
    • ํ•˜๋‚˜๋ผ๋„ ์„œ๋กœ ๊ฐ™์œผ๋ฉด ํƒˆ๋ฝ์ด ์•„๋‹˜.
    • ์ ์ˆ˜๋ฅผ ์ž˜ ์ •๋ ฌํ•˜๋ฉด ๋  ๊ฒƒ ๊ฐ™์€๋ฐ...
a = [[9,0],[9,1],[9,2],[8,1],[8,2],[8,3],[8,10],[7,1],[7,2],[7,3],[6,6],[5,5],[3,1],[3,2]]

a.sort(key=lambda x:(-sum(x))) #ํฐ ๊ฐ’๋ถ€ํ„ฐ
print(a)

#output
#[[8,10],[6,6],[9,2],[8,3],[9,1],[8,2],[7,3],[5,5],[9,0],[8,1],[7,2],[7,1],[3,2],[3,1]]

a.sort(key=lambda x:(-x[0],x[1])) #ํฐ ๊ฐ’๋ถ€ํ„ฐ
print(a)

#output
#[[9,0],[9,1],[9,2],[8,1],[8,2],[8,3],[8,10],[7,1],[7,2],[7,3],[6,6],[5,5],[3,1],[3,2]]

a.sort(key=lambda x:(x[0],-x[1])) #ํฐ ๊ฐ’๋ถ€ํ„ฐ
print(a)

#output
#[[3,2],[3,1],[5,5],[6,6],[7,3],[7,2],[7,1],[8,10],[8,3],[8,2],[8,1],[9,2],[9,1],[9,0]]

a.sort(key=lambda x:(-x[0],-x[1])) #ํฐ ๊ฐ’๋ถ€ํ„ฐ
print(a)

#output
#[[9,2],[9,1],[9,0],[8,10],[8,3],[8,2],[8,1],[7,3],[7,2],[7,1],[6,6],[5,5],[3,2],[3,1]]
  • [9,2]๋ฅผ ๋„ฃ๊ณ , [9,1], [9,0]์€ ๊ฐ™์€ 9๋‹ˆ๊นŒ ๋„˜์–ด๊ฐ€๊ณ ,
  • ์•ž์ž๋ฆฌ๊ฐ€ 8๋กœ ๋ฐ”๋€Œ๋ฉด, [9,2]๋ž‘ [8,10]์ด๋ž‘ ์ฒดํฌํ•ด์„œ ๋‘˜ ๋‹ค ์ž‘์œผ๋ฉด ํƒˆ๋ฝ,
  • ๋‘˜ ๋‹ค ์ž‘์ง€ ์•Š์œผ๋ฉด [8,10]์„ ์ถ”๊ฐ€ํ•˜๊ณ , [8,3],[8,2],[8,1]์„ ๋น„๊ต
  • [9,2],[8,10]์ด๋ž‘ ๋น„๊ตํ•˜๋ฉด [8,1] ํƒˆ๋ฝ.
  • [7,3]์œผ๋กœ ๋„˜์–ด๊ฐ€์„œ, [9,2],[8,10]์ด๋ž‘ ๋น„๊ตํ•˜๋ฉด 7,3๋„ ํƒˆ๋ฝ. ๊ทธ ๋ฐ‘์œผ๋กœ ๋‹ค ํƒˆ๋ฝ,
  • [6,6]์œผ๋กœ ๋„˜์–ด๊ฐ€์„œ, [9,2],[8,10]์ด๋ž‘ ๋น„๊ตํ•˜๋ฉด [6,6]๋„ ํƒˆ๋ฝ,
  • [5,5]๋กœ ๋„˜์–ด๊ฐ€์„œ ํƒˆ๋ฝ...
  • ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ์ข€ ์ ๊ฒŒ ๋น„๊ตํ•˜๋ ค๋‚˜?
def solution(scores):
    ์™„ํ˜ธ์˜ํƒœ๋„์ ์ˆ˜, ์™„ํ˜ธ์˜ํ‰๊ฐ€์ ์ˆ˜ = scores.pop(0)
    ์™„ํ˜ธ์˜์ด์  = ์™„ํ˜ธ์˜ํƒœ๋„์ ์ˆ˜ + ์™„ํ˜ธ์˜ํ‰๊ฐ€์ ์ˆ˜
    
    scores = [x for x in scores if sum(x) > ์™„ํ˜ธ์˜์ด์ ] #์™„ํ˜ธ์˜ ์ด์ ๋ณด๋‹ค ๋‚ฎ๊ฑฐ๋‚˜ ๊ฐ™์€ ์ ์ˆ˜ ์ œ๊ฑฐ
    
    answer = len(scores) + 1
    if len(scores) == 0: #ํ•จ์ •์ด ์ด๊ฑฐ์˜€์–ด? ใ…ก.ใ…ก;
        return answer
    
    scores.sort(key=lambda x:(-x[0],-x[1])) #ํฐ ๊ฐ’๋ถ€ํ„ฐ
    
    for ์ ์ˆ˜ in scores:
        if ์™„ํ˜ธ์˜ํƒœ๋„์ ์ˆ˜ < ์ ์ˆ˜[0] and ์™„ํ˜ธ์˜ํ‰๊ฐ€์ ์ˆ˜ < ์ ์ˆ˜[1]:
            return -1
    
    ๋†’์€์ ์ˆ˜ = []
    ๋†’์€์ ์ˆ˜.append(scores.pop(0))
    
    for ์ ์ˆ˜ in scores:
        #print(scores, answer, "๋†’์ ", ๋†’์€์ ์ˆ˜, "์ง€๊ธˆ์ฒดํฌํ•˜๋Š” ์ ์ˆ˜", ์ ์ˆ˜)
        for ๋†’์  in ๋†’์€์ ์ˆ˜:
            #print(๋†’์ , ์ ์ˆ˜, end="  ")
            if ๋†’์ [0] > ์ ์ˆ˜[0]:
                if ๋†’์ [1] > ์ ์ˆ˜[1]: #์ด ์ ์ˆ˜ ๋ฐ‘์œผ๋กœ ๋‹ค ํƒˆ๋ฝ
                    #print("ํƒˆ๋ฝ")
                    answer -= 1
                    break
                else:
                    #print("์ ์ˆ˜๋“ฑ๋ก")
                    ๋†’์€์ ์ˆ˜.append(์ ์ˆ˜)
            #print(" ")
    return answer
    
์ •ํ™•์„ฑ  ํ…Œ์ŠคํŠธ
ํ…Œ์ŠคํŠธ 1 ใ€‰	ํ†ต๊ณผ (0.00ms, 10.4MB)
ํ…Œ์ŠคํŠธ 2 ใ€‰	ํ†ต๊ณผ (0.00ms, 10.3MB)
ํ…Œ์ŠคํŠธ 3 ใ€‰	ํ†ต๊ณผ (0.01ms, 10.4MB)
ํ…Œ์ŠคํŠธ 4 ใ€‰	ํ†ต๊ณผ (0.01ms, 10.2MB)
ํ…Œ์ŠคํŠธ 5 ใ€‰	ํ†ต๊ณผ (0.01ms, 10.3MB)
ํ…Œ์ŠคํŠธ 6 ใ€‰	ํ†ต๊ณผ (0.01ms, 10.3MB)
ํ…Œ์ŠคํŠธ 7 ใ€‰	ํ†ต๊ณผ (0.01ms, 10.3MB)
ํ…Œ์ŠคํŠธ 8 ใ€‰	ํ†ต๊ณผ (0.01ms, 10.3MB)
ํ…Œ์ŠคํŠธ 9 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.5MB)
ํ…Œ์ŠคํŠธ 10 ใ€‰	ํ†ต๊ณผ (0.04ms, 10.3MB)
ํ…Œ์ŠคํŠธ 11 ใ€‰	ํ†ต๊ณผ (1.81ms, 10.3MB)
ํ…Œ์ŠคํŠธ 12 ใ€‰	ํ†ต๊ณผ (0.10ms, 10.4MB)
ํ…Œ์ŠคํŠธ 13 ใ€‰	ํ†ต๊ณผ (0.13ms, 10.3MB)
ํ…Œ์ŠคํŠธ 14 ใ€‰	ํ†ต๊ณผ (0.27ms, 10.4MB)
ํ…Œ์ŠคํŠธ 15 ใ€‰	ํ†ต๊ณผ (0.52ms, 10.7MB)
ํ…Œ์ŠคํŠธ 16 ใ€‰	ํ†ต๊ณผ (157.25ms, 16.8MB)
ํ…Œ์ŠคํŠธ 17 ใ€‰	ํ†ต๊ณผ (1.82ms, 11.5MB)
ํ…Œ์ŠคํŠธ 18 ใ€‰	ํ†ต๊ณผ (1.25ms, 11.4MB)
ํ…Œ์ŠคํŠธ 19 ใ€‰	ํ†ต๊ณผ (7.50ms, 17.4MB)
ํ…Œ์ŠคํŠธ 20 ใ€‰	ํ†ต๊ณผ (5.29ms, 17.9MB)
ํ…Œ์ŠคํŠธ 21 ใ€‰	ํ†ต๊ณผ (8.75ms, 18.6MB)
ํ…Œ์ŠคํŠธ 22 ใ€‰	ํ†ต๊ณผ (2588.67ms, 122MB)
ํ…Œ์ŠคํŠธ 23 ใ€‰	ํ†ต๊ณผ (33.99ms, 27.4MB)
ํ…Œ์ŠคํŠธ 24 ใ€‰	ํ†ต๊ณผ (97.93ms, 29.2MB)
ํ…Œ์ŠคํŠธ 25 ใ€‰	์‹คํŒจ (์‹œ๊ฐ„ ์ดˆ๊ณผ)
  • ๋งˆ์ง€๋ง‰๊ฑฐ ๋„ˆ๋ฌดํ–ˆ๋‹ค. ใ…ก.ใ…ก;
  • ์–ด๋–ป๊ฒŒ ํ’€์–ด ใ… .ใ… 
  • ๊ทผ๋ฐ ์ž ๋งŒ... ์ ์ˆ˜[0]์€ ๋น„๊ต ์•ˆํ•ด๋„ ๋˜์ง€ ์•Š๋‚˜?
  • ์ ์ˆ˜[0]์œผ๋กœ ์ •๋ ฌ๋˜์–ด ์žˆ๊ณ , ์ ์  ์ž‘์•„์ง€๋‹ˆ๊นŒ... ์ ์ˆ˜[1]๋งŒ ๋น„๊ตํ•˜๋ฉด ๋  ๊ฒƒ ๊ฐ™๋‹ค. ์•ˆ๋˜๋„ค? ใ…‹ใ…‹ใ…‹

๋„์ €ํžˆ ์•ˆ๋˜๊ฒ ๋‹ค. ์ปจ๋‹ ์ข€ ํ•˜์ž.ใ…‹ใ…‹ใ…‹

์•„... ์ด๋ ‡๊ฒŒ ํ•ด์•ผ๋˜๋Š”๊ตฌ๋‚˜...
#output
#[[9,0],[9,1],[9,2],[8,1],[8,2],[8,3],[8,10],[7,1],[7,2],[7,3],[6,6],[5,5],[3,1],[3,2]]

  • ์ ์ˆ˜[0]์ด ๊ฐ™์„ ๋•Œ๋Š” ๊ทธ๋ƒฅ ๋„˜์–ด๊ฐ€๊ณ , ์ ์ˆ˜[0]์ด ๋‹ฌ๋ผ์ง€๋ฉด ์ ์ˆ˜ ๊ฐฑ์‹ .
  • ๊ทธ๋Ÿฌ๋ฉด ์‹œ์ž‘ํ•ด๋ณด๋ฉด
  • [9,0]์ด ์ดˆ๊ธฐ๊ฐ’
    • [9,1],[9,2] ๋Š” 9๊ฐ€ ๊ฐ™์œผ๋‹ˆ๊นŒ ๋†’์€์ ์ˆ˜๋ฅผ ๊ฐฑ์‹ ํ•˜๋ฉด์„œ ๋„˜์–ด๊ฐ. ๋งˆ์ง€๋ง‰[9,2]
  • [8,1]๋ถ€ํ„ฐ ์ ์ˆ˜[0]์ด ๋‹ฌ๋ผ์ง. ๋งˆ์ง€๋ง‰[9,2]๋ž‘ ๋น„๊ตํ•˜๋ฉด
    • [8,1] ํƒˆ๋ฝ
    • [8,2],[8,3],[8,10]์•ˆํƒˆ๋ฝ, ์ ์ˆ˜ ๊ฐฑ์‹ . ๋งˆ์ง€๋ง‰ [8,10]

์•„... ์ด๋ ‡๊ฒŒ ํ•˜๋Š”๊ฑฐ์˜€๊ตฌ๋‚˜. ใ… .ใ… 

def solution(scores):
    ์™„ํ˜ธ์˜ํƒœ๋„์ ์ˆ˜, ์™„ํ˜ธ์˜ํ‰๊ฐ€์ ์ˆ˜ = scores.pop(0)
    ์™„ํ˜ธ์˜์ด์  = ์™„ํ˜ธ์˜ํƒœ๋„์ ์ˆ˜ + ์™„ํ˜ธ์˜ํ‰๊ฐ€์ ์ˆ˜
    
    scores = [x for x in scores if sum(x) > ์™„ํ˜ธ์˜์ด์ ] #์™„ํ˜ธ์˜ ์ด์ ๋ณด๋‹ค ๋‚ฎ๊ฑฐ๋‚˜ ๊ฐ™์€ ์ ์ˆ˜ ์ œ๊ฑฐ
    
    answer = len(scores) + 1
    if len(scores) == 0: #ํ•จ์ •์ด ์ด๊ฑฐ์˜€์–ด? ใ…ก.ใ…ก;
        return answer
    
    scores.sort(key=lambda x:(-x[0],x[1])) #ํฐ ๊ฐ’๋ถ€ํ„ฐ
    
    for ์ ์ˆ˜ in scores:
        if ์™„ํ˜ธ์˜ํƒœ๋„์ ์ˆ˜ < ์ ์ˆ˜[0] and ์™„ํ˜ธ์˜ํ‰๊ฐ€์ ์ˆ˜ < ์ ์ˆ˜[1]:
            return -1
    
    ๋†’์€์ ์ˆ˜ = []
    ๋†’์€์ ์ˆ˜ = scores.pop(0)
    
    for ์ ์ˆ˜ in scores:
        if ๋†’์€์ ์ˆ˜[0] == ์ ์ˆ˜[0]:
            ๋†’์€์ ์ˆ˜[1] = ์ ์ˆ˜[1]
        else:
            if ๋†’์€์ ์ˆ˜[1] > ์ ์ˆ˜[1]:
                answer -= 1
            else:
                ๋†’์€์ ์ˆ˜ = ์ ์ˆ˜
        
    return answer
    
์ •ํ™•์„ฑ  ํ…Œ์ŠคํŠธ
ํ…Œ์ŠคํŠธ 1 ใ€‰	ํ†ต๊ณผ (0.00ms, 10.4MB)
ํ…Œ์ŠคํŠธ 2 ใ€‰	ํ†ต๊ณผ (0.00ms, 10.2MB)
ํ…Œ์ŠคํŠธ 3 ใ€‰	ํ†ต๊ณผ (0.01ms, 10.3MB)
ํ…Œ์ŠคํŠธ 4 ใ€‰	ํ†ต๊ณผ (0.01ms, 10.5MB)
ํ…Œ์ŠคํŠธ 5 ใ€‰	ํ†ต๊ณผ (0.00ms, 10.2MB)
ํ…Œ์ŠคํŠธ 6 ใ€‰	ํ†ต๊ณผ (0.01ms, 10.3MB)
ํ…Œ์ŠคํŠธ 7 ใ€‰	ํ†ต๊ณผ (0.01ms, 10.4MB)
ํ…Œ์ŠคํŠธ 8 ใ€‰	ํ†ต๊ณผ (0.01ms, 10.3MB)
ํ…Œ์ŠคํŠธ 9 ใ€‰	ํ†ต๊ณผ (0.02ms, 10.3MB)
ํ…Œ์ŠคํŠธ 10 ใ€‰	ํ†ต๊ณผ (0.02ms, 10.2MB)
ํ…Œ์ŠคํŠธ 11 ใ€‰	ํ†ต๊ณผ (0.35ms, 10.4MB)
ํ…Œ์ŠคํŠธ 12 ใ€‰	ํ†ต๊ณผ (0.11ms, 10.4MB)
ํ…Œ์ŠคํŠธ 13 ใ€‰	ํ†ต๊ณผ (0.23ms, 10.4MB)
ํ…Œ์ŠคํŠธ 14 ใ€‰	ํ†ต๊ณผ (0.18ms, 10.3MB)
ํ…Œ์ŠคํŠธ 15 ใ€‰	ํ†ต๊ณผ (1.11ms, 10.7MB)
ํ…Œ์ŠคํŠธ 16 ใ€‰	ํ†ต๊ณผ (2.35ms, 10.9MB)
ํ…Œ์ŠคํŠธ 17 ใ€‰	ํ†ต๊ณผ (0.96ms, 11.4MB)
ํ…Œ์ŠคํŠธ 18 ใ€‰	ํ†ต๊ณผ (0.98ms, 11.4MB)
ํ…Œ์ŠคํŠธ 19 ใ€‰	ํ†ต๊ณผ (7.07ms, 17.6MB)
ํ…Œ์ŠคํŠธ 20 ใ€‰	ํ†ต๊ณผ (9.47ms, 17.8MB)
ํ…Œ์ŠคํŠธ 21 ใ€‰	ํ†ต๊ณผ (9.73ms, 18.8MB)
ํ…Œ์ŠคํŠธ 22 ใ€‰	ํ†ต๊ณผ (36.20ms, 26.7MB)
ํ…Œ์ŠคํŠธ 23 ใ€‰	ํ†ต๊ณผ (25.55ms, 26.6MB)
ํ…Œ์ŠคํŠธ 24 ใ€‰	ํ†ต๊ณผ (56.88ms, 28.1MB)
ํ…Œ์ŠคํŠธ 25 ใ€‰	ํ†ต๊ณผ (20.80ms, 26.2MB)
  • ์ •๋ ฌ์„ ์–ด๋–ป๊ฒŒ ํ•˜๋Š”๊ฐ€๊ฐ€ ๊ฐ€์žฅ ์ค‘์š”ํ•œ ๋ฌธ์ œ์˜€๋‹ค.
  • ์—‰๋šฑํ•˜๊ฒŒ ์ •๋ ฌํ•ด๋†“๊ณ , ๊ทธ ๊ตฌ์กฐ๋กœ ํ’€๋ ค๊ณ  ๋จธ๋ฆฌ๋ฅผ ์•„๋ฌด๋ฆฌ ๊ตด๋ ค๋„ ๋˜์งˆ ์•Š์•„ ๊ณ ๋ฏผํ–ˆ๋‹ค.
  • ๋‹ค์Œ๋ถ€ํ„ฐ 2์ˆ˜๋ฅผ ๋น„๊ตํ•˜๋Š” ๋ฌธ์ œ๊ฐ€ ๋‚˜์˜ค๋ฉด ๋ฌด์กฐ๊ฑด ์ € ๋žŒ๋‹ค ํ•จ์ˆ˜๋กœ ์ •๋ ฌํ•ด์„œ ํ‘ธ๋Š” ๊ฑธ๋กœ...
  • ํ•˜์ง€๋งŒ ๋‚˜์ค‘์— ๋น„์Šทํ•œ ๋ฌธ์ œ๊ฐ€ ๋‚˜์˜ค๋ฉด ๊นŒ๋จน๊ณ  ๋˜ ์‚ฝ์งˆํ•˜๊ฒ ์ง€. ใ…‹ใ…‹ใ…‹

๊ณ ์ƒํ•œ ๋งŒํผ ์ ์ˆ˜๊ฐ€ ์ปค์„œ ๊ธฐ๋ถ„์ด ์ข‹๋‹ค. +5์  ์งœ๋ฆฌ ๋ฌธ์ œ ์˜€๋‹ค๋‹ˆ!

728x90
๋ฐ˜์‘ํ˜•