#K14371. Maximum Tasks Completed
Maximum Tasks Completed
Maximum Tasks Completed
Alice is given a set of tasks. Each task has a deadline and requires a certain amount of time (duration) to complete. Alice must complete any task before or on its deadline. Your task is to determine the maximum number of tasks that Alice can finish without missing their deadlines.
An optimal strategy is to sort the tasks in increasing order of deadlines and then, starting from time 0, greedily attempt each task if the total time used plus the task's duration does not exceed its deadline. Formally, if the current accumulated time is currentTime and the next task requires t units of time with deadline d, then the task can be completed if:
$$ currentTime + t \le d $$Implement this strategy to solve the problem.
inputFormat
The first line contains a single integer N (1 ≤ N ≤ 10^5), the number of tasks.
The second line contains N space-separated integers representing the deadlines of the tasks.
The third line contains N space-separated integers representing the durations of the tasks.
outputFormat
Output a single integer representing the maximum number of tasks that can be completed without missing their deadlines.
## sample4
4 2 5 8
2 1 3 2
3