best
to keep track of the best profit seen so far, and a variable i
to iterate through the jobs.i
is less than the length of the jobs list and the worker's ability is greater than or equal to the difficulty of the i
th job, update best
to be the maximum of best
and the profit of the i
th job, and increment i
.
b. Add the value of best
to the total profit.