백준 16938 캠프 준비

gmlwlswldbs·2021년 12월 22일
0

코딩테스트

목록 보기
93/130
n, l, r, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
cnt = 0
def go(index, q):
    global cnt
    if index == n:
        if len(q) >= 2:
            if l <= sum(q) <= r and q[-1]-q[0] >= x:
                cnt += 1
        return
    go(index+1, q+[a[index]])
    go(index+1, q)

go(0, [])

print(cnt)

n제한이 15라 먼저 sort해주었다 (나중에 최대 최소 ㅃㅏ르게 하려고...?)

0개의 댓글