Lv.3greedyheapsorting
Job Sequencing with Deadlines
- Memory limit
- 256 MB
- Correctness time limit
- 10000 ms
- Solvers
- 0
Job i takes one day and pays profits[i] if finished on or before day deadlines[i]. One job per day, starting on day 1.
Return the maximum total profit.
Examples
| deadlines | profits | result |
|---|---|---|
[2, 1, 2, 1, 3] | [100, 19, 27, 25, 15] | 142 |
[1, 1, 1] | [5, 9, 2] | 9 |
[1000000000] | [7] | 7 |
Efficiency
This problem has performance tests. Judge the required time complexity from the input sizes in the constraints.
Function signature
solution(deadlines: int[], profits: int[]) → long
Constraints
- ,
deadlines[i],profits[i]; the answer can exceed 32 bits.
Expected complexity
- Time
- O(N log N)
- Space
- O(N)
Examples
| deadlines | profits | Expected |
|---|---|---|
[2,1,2,1,3] | [100,19,27,25,15] | 142 |
[1,1,1] | [5,9,2] | 9 |
[1000000000] | [7] | 7 |
Hint
Hint
Process jobs by deadline, keep the chosen profits in a min-heap and drop the smallest whenever the heap outgrows the current deadline; sum what remains. Searching day by day for the latest free slot is .
Time limits per language
| Language | Efficiency time limit | |
|---|---|---|
| C (GCC, gnu17) | 200 ms | estimated |
| C++ (GCC, gnu++23) | 200 ms | derived |
| Python 3.13 | 1000 ms | derived |
| Java 25 | 1268 ms | derived |
| Kotlin 2.4 (JVM) | 1400 ms | estimated |
| C# 14 (.NET 10) | 1400 ms | estimated |
Test groups
| Group | Weight | Tests | Visibility |
|---|---|---|---|
| sample | 0 | 3 | inputs and outputs |
| correctness | 40 | 8 | verdict only |
| performance | 60 | 4 | verdict only |