-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTelescopeScheduling.py
88 lines (56 loc) · 1.46 KB
/
TelescopeScheduling.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import sys
#m_file = open("tele_in.txt","r")
tests = sys.stdin.readline().strip()
init_time = float('inf')
f_time = 0
start_dict = {} # Keys are times
end_dict = {} # Keys are stars
desire_dict = {} # Keys are stars
times = []
maxD = 0
def recurse(time_index,desire,cur_star_desire,cur_star_end):
global maxD
time = times[time_index]
while time < f_time:
if time >= cur_star_end:
cur_star_desire = -1
cur_star_end = -1
if time in start_dict:
if cur_star_desire == -1:
cur_star_desire = desire_dict[start_dict[time][0]]
if len(start_dict[time]) > 1:
for i in start_dict[time][1:]:
new_desire = desire_dict[i]
recurse(time_index+1,desire+new_desire,new_desire,end_dict[i])
desire += cur_star_desire
cur_star_end = end_dict[start_dict[time][0]]
else:
for i in start_dict[time]:
new_desire = desire_dict[i]
recurse(time_index+1,desire+new_desire-cur_star_desire,new_desire,end_dict[i])
time_index += 1
time = times[time_index]
if desire > maxD:
maxD = desire
index = 0
for line in sys.stdin:
line = line.strip().split(" ")
S = int(line[0])
F = int(line[1])
D = int(line[2])
if S in start_dict:
start_dict[S].append(index)
else:
start_dict[S] = [index]
end_dict[index] = F
desire_dict[index] = D
if S < init_time:
init_time = S
if F > f_time:
f_time = F
times.append(S)
index += 1
times.append(float("inf"))
times = sorted(list(set(times)))
recurse(0,0,-1,-1)
print(maxD)