There are n
jobs that can be executed in parallel on a processor, where the execution time of the i-th
job is executionTime[i]
. To speed up execution, the following strategy is used.
- In one operation, a job is chosen, the major job, and is executed for
x
seconds. - All other jobs are executed for
y
seconds wherey < x
.
A job is complete when it has been executed for at least executionTime[i]
seconds, then it exits the pool. Find the minimum number of operations s
in which the processor can completely execute all the jobs if run optimally.
Example
Consider n = 5
, executionTime = [3, 4, 1, 7, 6]
, x = 4
and y = 2
.
The following strategy is optimal using 1-based indexing:
- Choose job
4
as the major job and reduce the execution times of job4
byx = 4
and other jobs byy = 2
.- New
executionTime = [1, 2, -1, 3, 4]
- Job
3
is complete, so it is removed.
- New
- Choose job
4
again.- New
executionTime = [-1, 0, -1, -1, 2]
- Jobs
1
,2
, and4
are now complete.
- New
- Choose job
5
.- New
executionTime = [-1, -1, -1, -1, -1]
- Job
5
is complete.
- New
The total number of operations required is 3.
Given a tree with n
nodes, rooted at node 0
(nodes are numbered from 0
to n-1
), with values assigned to nodes such that values[i]
denotes the value of node i
, find the maximal sum of values along any downward path starting at some node u
and going only down the tree. In other words, only consider child nodes u1, u2, u3, ... uk
where each node ui
is a direct child of node u
(1 ≤ k ≤ r
).
For example, given the following tree (labeled as node number/value
):
0/5
/ \
1/7 3/4
/ \
2/-10 4/15
Possible paths:
0 → 1 → 2 → 3
has a sum of5 + 7 + (-10) + 4 = 6
1 → 2 → 3
has a sum of7 + (-10) + 4 = 1
- The highest sum path is
0 → 4
with a sum of5 + 15 = 20
.
Function Description
Complete the function bestSumDownwardTreePath in the editor below.
It must return an integer that denotes the largest sum of values along a path down the tree from some node u
.
我们长期稳定承接各大科技公司如TikTok、Google、Amazon等的OA笔试代写服务,确保满分通过。如有需求,请随时联系我们。
We consistently provide professional online assessment services for major tech companies like TikTok, Google, and Amazon, guaranteeing perfect scores. Feel free to contact us if you're interested.
