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
'🟢 알고리즘 문제 풀이 > Baekjoon' 카테고리의 다른 글
| [파이썬] 백준 1753 최단경로 (0) | 2023.04.30 |
|---|---|
| [파이썬] 백준 14502 연구소 (0) | 2023.04.28 |
| [파이썬] 백준 2595 부등호 (0) | 2023.04.13 |
| [파이썬] 백준 4811 알약 (0) | 2023.04.11 |
| [파이썬] 백준 14179 빗물 (0) | 2023.04.10 |