#P8838. Lexicographically Minimal Server Assignment
Lexicographically Minimal Server Assignment
Lexicographically Minimal Server Assignment
You are given \(n\) servers where the \(i\)-th server can process at most \(a_i\) units of data. There are also \(k\) commands, where the \(i\)-th command sends \(b_i\) units of data. For each command, you must assign an idle (unused) server such that the assigned server \(p_i\) can handle the data, i.e. \(a_{p_i} \ge b_i\).
Your task is to determine an assignment sequence \(p_1, p_2, \ldots, p_k\) such that the sequence is valid and lexicographically smallest among all valid assignments. If no valid assignment exists, output "-1".
Constraints: \(n, k \le 6\) and \(a_i, b_i \le 10\) for all valid indices.
inputFormat
The input consists of three lines:
- The first line contains two integers \(n\) and \(k\) separated by a space.
- The second line contains \(n\) integers \(a_1, a_2, \ldots, a_n\) representing the maximum data capacity for each server.
- The third line contains \(k\) integers \(b_1, b_2, \ldots, b_k\) representing the amount of data for each command.
outputFormat
If a valid assignment exists, output \(k\) integers \(p_1, p_2, \ldots, p_k\) separated by spaces representing the assigned server indexes (1-indexed) for each command, where the sequence is lexicographically smallest. Otherwise, output "-1".
sample
3 2
4 5 6
5 4
2 1