#C7211. Service Request Assignment
Service Request Assignment
Service Request Assignment
You are given N nodes and M service requests. Each node has a capacity and each request demands a certain amount of capacity. The problem is to determine whether all service requests can be assigned to the nodes such that no node's total demand exceeds its capacity.
Formally, you are given two sequences:
- Capacities: \(c_1, c_2, \dots, c_N\) where \(c_i\) is the capacity of the \(i\)-th node.
- Demands: \(d_1, d_2, \dots, d_M\) where \(d_j\) is the required capacity for the \(j\)-th request.
You must decide whether it is possible to assign each of the \(M\) requests to one of the \(N\) nodes such that after assigning a request to a node, the node's remaining capacity (i.e. its original capacity minus the sum of demands assigned to it) remains non-negative.
The assignment strategy in the sample solution is greedy: both capacities and demands are sorted in descending order, and each demand is matched with the smallest index node (in the sorted order) that can accommodate it. Output "Possible" if all requests can be assigned; otherwise, output "Impossible".
inputFormat
The input is provided via standard input (stdin) as a sequence of integers separated by spaces and/or newlines.
The first two integers are:
- N: the number of nodes.
- M: the number of service requests.
This is followed by N integers representing the capacities of the nodes, and then M integers representing the demands of the service requests.
Example:
3 4 6 7 8 4 3 5 2
outputFormat
Output a single string to standard output (stdout): either "Possible" if all service requests can be assigned to nodes without exceeding their capacity, or "Impossible" otherwise.
## sample3 4 6 7 8 4 3 5 2
Possible