#QHD0000061. Giải mã hóa đơn gọi món (Restaurant Orders)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Giải mã hóa đơn gọi món (Restaurant Orders)
Restaurant Orders
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
A restaurant menu has types of dishes. Type costs kronor and has index (-based). Customers may order any number of copies of each type; two plates of type count as two copies of item .
For each of receipts, the waiter remembers only the total cost , not the items ordered. Determine whether that total can be formed by no multiset of menu items, exactly one multiset, or more than one multiset.
Two orders are identical when they contain the same multiplicity of each menu type; the ordering of the plates does not matter. Even when two menu items have equal prices, their different indices make them different types.
Print Impossible if no order exists, Ambiguous if at least two distinct orders exist, or list the item indices of the unique order in nondecreasing order. Repeat indices when copies were ordered. Receipt queries are independent and use the same menu.
Input
Line 1 contains . Line 2 contains the item prices . Line 3 contains . Line 4 contains the receipt totals .
Output
Print exactly lines. For receipt , print Impossible, Ambiguous, or the item indices of the unique order in ascending order, separated by spaces. Do not print any count or explanatory text.
Subtasks
-
Subtask 1 (20 points): , for every , , for every .
-
Subtask 2 (30 points): , for every , , for every .
-
Subtask 3 (50 points): , for every , , for every .
Examples
Input
3
4 5 8
3
11 13 14
Output
Impossible
Ambiguous
1 2 2
Explanation
Menu prices are . No nonnegative combination sums to , so the first line is Impossible. At , both and are valid, so the answer is Ambiguous. At , only is possible, so print the indices 1 2 2.