-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfairworkload.py
44 lines (31 loc) · 994 Bytes
/
fairworkload.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
__author__ = "Shashwat Tiwari"
__email__ = "shashwat1791@gmail.com"
"""
Reference: https://community.topcoder.com/stat?c=problem_statement&pm=1901&rd=4650
"""
class FairWorkload:
def get_workers_for_current_paritions(self, folders, workers, max_allocation_per_worker):
worker = 1
target = folders[0]
for i in range(1, len(folders)):
target += folders[i]
if target > max_allocation_per_worker:
target = folders[i]
worker += 1
return worker
def getMostWork(self, folders, workers):
low = max(folders)
high = sum(folders)
while low < high:
mid = (low + (high-low)//2)
current_workers = self.get_workers_for_current_paritions(folders, workers, mid)
if current_workers <= workers:
high = mid
else:
low = mid + 1
return low
if __name__ == "__main__":
folders = [568, 712, 412, 231, 241, 393, 865, 287, 128, 457, 238, 98, 980, 23, 782]
workers = 4
res = FairWorkload().getMostWork(folders, workers)
print(res)