#C8831. Reorder Tasks Based on Priority and Criticality
Reorder Tasks Based on Priority and Criticality
Reorder Tasks Based on Priority and Criticality
You are given ( n ) tasks. Each task has a priority and a critical flag. The priorities are provided as a list ( P = [p_1, p_2, \ldots, p_n] ) and the critical flags as a list ( C = [c_1, c_2, \ldots, c_n] ) where ( c_i ) is either 0 (non-critical) or 1 (critical). Your task is to reorder the tasks so that all critical tasks appear first in the order they appeared in the input, followed by the non-critical tasks sorted in ascending order by their priority values. This means if a task is critical, its position in the output remains as in the input relative to the other critical tasks, and if it is not, then it should be placed after all critical tasks in sorted order.
inputFormat
The input is read from standard input (stdin) and consists of three lines:\
- The first line contains an integer ( n ) representing the number of tasks.\
- The second line contains ( n ) space-separated integers representing the priority values ( P = [p_1, p_2, \ldots, p_n] ).\
- The third line contains ( n ) space-separated integers representing the critical flags ( C = [c_1, c_2, \ldots, c_n] ) (where 1 indicates a critical task, and 0 indicates a non-critical task).
outputFormat
Output to standard output (stdout) a single line of ( n ) space-separated integers representing the reordered list of task priorities. First, all critical tasks should appear in their original order, followed by the non-critical tasks sorted in ascending order.## sample
5
4 2 5 1 3
0 1 0 1 0
2 1 3 4 5