얼렁뚱땅 백준 문제풀이
[백준 문제풀이] 얼렁뚱땅 6159번 코스튬파티 풀이
MOSTAR
2022. 5. 16. 17:32
n,s = map(int,input().split())
cow_list = [int(input()) for i in range(n)]
cow_list.sort(reverse=True)
def binary(cow_list, index_) :
target = cow_list[index_]
cow_list_new = list(cow_list)[index_+1:]
start = 0
end = len(cow_list_new) - 1
hello = -1
while True :
if start>end :
break
mid = (start + end) // 2
if target + cow_list_new[mid] <= s :
hello = mid
end = mid - 1
elif target + cow_list_new[mid] > s :
start = mid + 1
if hello == -1 :
ok = 0
else :
ok = len(cow_list_new) - hello
return ok
all = 0
for i in range(len(cow_list)-1) :
all += binary(cow_list,i)
print(all)
사실은 틀려따 ㅎㅋ
근데 어디가 틀린지 모르겟다 ㅜ
-------------------------------------
고쳤다 어떻게 고쳤냐면,
만약 수가 다 다르다면 ==일떄를 다르게 두어도 되지만,
중복이 있을 수 있따면 머리 잘 굴려서 <여기나 >여기에 넣어야한다