A highly anticipated examination is scheduled for tomorrow morning.
For the past week, social media has been flooded with rumors about leaked papers, secret answer keys, and "100% reliable sources."
The paper definitely wasn't leaked to you, so now you must actually study.
There are n chapters remaining in the syllabus.
For each chapter:
time[i] represents the number of hours required to revise chapter i.marks[i] represents the marks you can gain by revising chapter i.You have only h hours left before the exam.
You may revise a chapter at most once, and partial revision is not allowed.
Return the maximum total marks you can gain by selecting an optimal set of chapters to revise without exceeding the available time.
As the exam draws closer, you realize an important truth:
Platform may be banned, but your panic is still fully operational.
time = [2, 3, 1]
marks = [20, 30, 15]
h = 445You can revise:
Total time used:
3 + 1 = 4Total expected marks:
30 + 15 = 45No other valid selection yields more marks.
time = [4, 2, 3]
marks = [50, 20, 40]
h = 560Revise chapters 1 and 2.
Time = 2 + 3 = 5
Marks = 20 + 40 = 60Although chapter 0 gives 50 marks, combining chapters 1 and 2 produces a better result.
time = [5, 6, 7]
marks = [10, 20, 30]
h = 40There is not enough time to revise any chapter.
1 <= n <= 1000
n == time.length == marks.length
1 <= time[i] <= 1000
1 <= marks[i] <= 1000
1 <= h <= 1000The most time-consuming part of exam preparation is not studying.
It's deciding what not to study.
If you enjoyed the problem, consider an upvote!