인프런 영문 브랜드 로고
인프런 영문 브랜드 로고

Inflearn Community Q&A

hp456789943268's profile image
hp456789943268

asked

Introduction to Python Algorithm Problem Solving (Coding Test Preparation)

8. Sinking Titanic (Greedy)

5번 테스트 케이스에서 오류가 나는데 이유가 뭘까요??

Written on

·

196

0

'''

4-8 침몰하는 타이타닉

'''

import sys

#sys.stdin=open("in5.txt","rt")

n,m=map(int,input().split())

#print(n,m)

w=list(map(int,input().split()))

w.sort()

#print(w)

cnt=0 

lt=0

rt=n-1

while lt<=rt:

    if w[lt]+w[rt]<=m:

        cnt+=1

        lt+=1

        rt-=1

    else:

        rt-=1

        cnt+=1

print(cnt)

다른 케이스는 잘되는데 왜 마지막 케이스만 안될까요?

python코테 준비 같이 해요!

Answer 1

0

codingcamp님의 프로필 이미지
codingcamp
Instructor

문제가 없는 코드입니다. 제가 5번 데이터 해보니 561 정확하게 나옵니다. 채점해보아도 100점이 나오는 코드입니다.

hp456789943268's profile image
hp456789943268

asked

Ask a question