Lunch Break
Limits: 2 sec., 512 MiB
This statement was translated automatically from Ukrainian.
Having completed a quick errand for the Boss, Zenik got quite hungry. The local canteen is located in the far aisle of the office. Although the place is quite spacious and comfortable, there is one nuance — it is the only one. Such minor details are nothing compared to a hungry stomach.
There are a total of \(n\) employees in the company. Employee \(i\) (\(1 \le i \le n\)) plans to arrive for lunch at time moment \(t_i\) (furthermore, no two employees plan to arrive at the canteen at the exact same time) and will eat their lunch for \(s_i\) time. Under such circumstances, there is a probability of a queue forming, so each employee has a certain waiting limit \(p_i\) — the maximum amount of time they can stand in the queue.
You are asked to find the number of employees who will actually manage to have lunch and output their numbers in the order of eating. Two people cannot have lunch simultaneously. You can neglect the time it takes for people to transition — if some employee finishes lunch at time \(t\), the next one can start at the exact same moment.
Input
The first line contains a single integer \(n\) — the number of company employees.
The second line contains \(n\) integers \(t_i\), where the \(i\)-th number denotes the arrival time for lunch of the \(i\)-th employee.
The third line contains \(n\) integers \(s_i\), where the \(i\)-th number denotes the duration of lunch of the \(i\)-th employee.
The fourth line contains \(n\) integers \(p_i\), where the \(i\)-th number denotes the maximum waiting time of the \(i\)-th employee.
Output
In the first line, output an integer \(k\) — the number of people who manage to have lunch.
In the second line, output \(k\) integers — the employee numbers in the order they had lunch.
Constraints
\(1 \leq n \leq 2 \cdot 10^5\),
\(1 \leq t_i, s_i, p_i \leq 10^8\),
All \(t_i\) are unique.
Scoring consists of the following blocks:
1 point for each sample test from the problem statement,
7 points: \(n \leq 15\), \(t_i < t_{i+1}\), \(t_i \leq 1000\), \(s_i \leq 1000\), \(p_i \leq 1000\),
10 points: \(n \leq 1000\), \(t_i < t_{i+1}\), \(t_i \leq 1000\), \(s_i \leq 1000\), \(p_i \leq 1000\),
16 points: \(n \leq 1000\), \(t_i < t_{i+1}\),
8 points: \(t_i + s_i < t_{i+1}\),
17 points: \(t_i < t_{i+1}\),
40 points: without additional constraints.
You will receive the points for a block only if your program passes all tests in that block.
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| 4 1 4 7 9 4 5 8 7 2 1 2 4 | 3 1 2 4 |
| Input (stdin) | Output (stdout) |
|---|---|
| 4 4 5 6 7 7 1 1 1 4 4 4 3 | 1 1 |
Notes
In the first example, the first employee arrives for lunch at time \(t_1 = 1\) and finishes their lunch at time \(t_1 + s_1 = 5\). The second employee arrives at time \(t_2 = 4\), but is forced to wait another 1 minute until the first employee finishes their lunch. Thus, the second employee will finish lunch at time \(5 + s_2 = 10\). The third employee arrives at time \(t_3 = 7\), their maximum waiting time is \(p_3 = 2\), meaning they leave the queue. Thus, the fourth employee arrives at \(t_4 = 9\), waits 1 min, and starts lunch.
In the second example, only the first employee will have lunch, everyone else will leave the canteen without waiting for their turn.
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|