Loading...
Loading...
You are given four integers tasks1, rest1, tasks2, and rest2 describing two workers who share one workstation. Worker 1 must finish tasks1 tasks and worker 2 must finish tasks2 tasks. Each task takes exactly one hour, and hours are numbered 1, 2, 3, and so on.
The rules are:
rest1.rest2.A worker who works during an hour finishes one task in it. An hour may also go unused.
Return the smallest T such that both workers can finish all of their tasks within hours 1 through T.
Input: tasks1 = 3, rest1 = 2, tasks2 = 1, rest2 = 3
Output: 5
Explanation: Worker 1 can't work during hours 2 and 4, so its three tasks need three odd hours. The first three odd hours are 1, 3 and 5, so T is at least 5. T = 5 works: worker 1 takes hours 1, 3 and 5, and worker 2 takes hour 2, which is not a multiple of 3.
Input: tasks1 = 1, rest1 = 2, tasks2 = 1, rest2 = 2
Output: 3
Explanation: Neither worker can work during an even hour. The two tasks need two different odd hours, and the first two are 1 and 3.
Input: tasks1 = 5, rest1 = 3, tasks2 = 5, rest2 = 3
Output: 14
Explanation: Neither worker can work during hours 3, 6, 9 and 12. Hours 1 through 14 contain 14 - 4 = 10 usable hours, exactly enough for all 10 tasks. Hours 1 through 13 contain only 9.
tasks1, tasks2 ≤109rest1, rest2 ≤104