-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathouter-wall.py
More file actions
36 lines (24 loc) · 1.05 KB
/
outer-wall.py
File metadata and controls
36 lines (24 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#https://programmers.co.kr/learn/courses/30/lessons/60062?language=python3
import itertools
def idx_noncycadj(n, r):
l = list(range(0,n-r+1))
return [[idx+num for idx, num in enumerate(combo)] for combo in itertools.combinations(l, r) if not (combo[0]==0 and combo[-1]==n-r)]
def solution(n, weak, dist):
m = len(weak)
if m==1: return 1
for r in range(1,len(dist)+1,1):
# r: number of people
if (r>=m): return m
for indices in itertools.combinations(list(range (m)), r): #idx_noncycadj(m, r):
maint_dist = [
weak[indices[i+1]-1]-weak[indices[i]] for i in range(r-1)
]
d = weak[indices[0]-1] - weak[indices[-1]]
if d<0: d += n
maint_dist.append(d)
maint_dist.sort()
isPossible = True
for i in range(1, r+1, 1):
if maint_dist[-i] > dist[-i]: isPossible=False
if isPossible: return r
return -1