This question evaluates algorithmic problem-solving in scheduling and combinatorial optimization, assessing understanding of capacity-constrained assignment, greedy or matching strategies, and correctness and complexity reasoning.
You are given an integer limit and two integer arrays required and optional of length n. For each day i, you must schedule required[i]. If time remains on that day (not exceeding limit), you may schedule at most one optional task; each optional task can be used at most once and can be assigned to any day. Goal: maximize the number of optional tasks scheduled across n days without exceeding the daily limit. Return: (