-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAQ.py
51 lines (38 loc) · 1.37 KB
/
AQ.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
sol_found = False
def reports_generation(list_hours, sumHours, partial_solution=[], idx=0, report=[]):
global sol_found
#Stop if a solution is found
if sol_found:
return
if idx == len(list_hours):
if sum(partial_solution) == sumHours:
report.append(partial_solution.copy())
sol_found = True
return
for element in list_hours[idx]:
partial_solution.append(element)
#Prune the partial solutions with an amount of hours > sumHours
if sum(partial_solution) <= sumHours:
reports_generation(list_hours, sumHours, partial_solution, idx + 1, report)
partial_solution.pop()
reports_generation(list_hours, sumHours, partial_solution, idx + 1, report)
return report
def main():
global sol_found
line1 = input().split()
d = int(line1[0])
sumHours = int(line1[1])
min_max_hours = []
list_hours = []
for i in range(d):
line = input().split()
min_max_hours.append((int(line[0]), int(line[1])))
list_hours.append(list(range(min_max_hours[-1][0], min_max_hours[-1][1] + 1)))
sol_found = False
reports = reports_generation(list_hours, sumHours)
if len(reports) == 0:
print("NO")
else:
print("YES")
print(" ".join(map(str, reports[0])))
main()