-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolve_b.py
38 lines (30 loc) · 968 Bytes
/
solve_b.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
from utils import parseINPUT, judgeFunction, generateSubmission
def cmp_function(book):
return T[book]
input = parseINPUT("b_read_on.txt")
B, L, D, B_value, N, T, M, N_n = input.values()
orderedLib = []
shippedBooks = []
# sort by the number of sign up days
orderBYsignup = [i for i in range(L)]
orderBYsignup.sort(key=cmp_function)
# iteration
curDay = 0
while curDay <= D:
# get the best lib
curLib = orderBYsignup[0]
orderBYsignup = orderBYsignup[1:]
if curDay + T[curLib] <= D:
curDay += T[curLib]
orderedLib.append(curLib)
sumBooks = min((D - curDay) * M[curLib], N_n[curLib])
shippedBooks += [N[curLib][:sumBooks]]
else:
break
print("cur day %d" % curDay)
submission = generateSubmission(orderedLib, shippedBooks)
# show score of the submission.
print(judgeFunction(submission, input["valueOFbook"]))
# write submission to file.
with open("b_answer.txt", "w") as f:
f.write(submission)