728x90

조합을 이용했고, 당연히 시간 초과가 날 줄 알았는데 안났다. 

import sys
from itertools import combinations
from collections import deque
import math
 
n,a,b,c = list(map(int,input().split(" ")))
 
# 난이도 합 a 이상 b 이하, 가장 어려운 거 - 가장 쉬운거 >=c
 
k = list(map(int,input().split(" ")))
 
k = list(sorted(k))
 
answer = 0
 
for i in range(2,len(k)+1):
    s = list(combinations(k,i))
 
    for j in range(0,len(s)):
        m = list(s[j])
 
        if c <= m[-1]-m[0] and a<=sum(m)<=b:
            answer+=1
 
print(answer)
 
 
728x90

+ Recent posts