Nayra is at a festival playing a game where the grand prize is a trip to Laguna Colorada. The game consists of using tokens to buy coupons. Buying a coupon may result in additional tokens. The goal is to get as many coupons as possible.
She starts the game with tokens.
There are
coupons, numbered from
to
.
Nayra has to pay
tokens (
) to buy coupon
(and she must have at least
tokens before the purchase).
She can buy each coupon at most once.
Moreover, each coupon (
) is assigned a type,
denoted by
,
which is an integer between
and
, inclusive.
After Nayra buys coupon
,
the remaining number of tokens she has gets multiplied by
.
Formally, if she has
tokens at some point of the game,
and buys coupon
(which requires
),
then she will have
tokens after the purchase.
Your task is to determine which coupons Nayra should buy and in what order, to maximize the total number of coupons she has at the end. If there is more than one sequence of purchases that achieves this, you may report any one of them.
Implementation Details
You should implement the following procedure.
std::vector<int> max_coupons(int A, std::vector<int> P, std::vector<int> T)
: the initial number of tokens Nayra has.
: an array of length
specifying the prices of the coupons.
: an array of length
specifying the types of the coupons.
- This procedure is called exactly once for each test case.
The procedure should return an array , which specifies Nayra's purchases as follows:
- The length of
should be the maximum number of coupons she can buy.
- The elements of the array are the indices of the coupons she should buy, in chronological order.
That is, she buys coupon
first, coupon
second, and so on.
- All elements of
must be unique.
If no coupons can be bought, should be an empty array.
Constraints
for each
such that
.
for each
such that
.
Subtasks
Subtask | Score | Additional Constraints |
---|---|---|
1 | ||
2 | ||
3 | ||
4 | ||
5 | Nayra can buy all |
|
6 | ||
7 | No additional constraints. |
Examples
Example 1
Consider the following call.
max_coupons(13, [4, 500, 8, 14], [1, 3, 3, 4])
Nayra initially has tokens. She can buy
coupons in the order shown below:
Coupon bought | Coupon price | Coupon type | Number of tokens after the purchase |
---|---|---|---|
In this example, it is not possible for Nayra to buy more than coupons,
and the sequence of purchases described above is the only way in which she can buy
of them.
Hence, the procedure should return
.
Example 2
Consider the following call.
max_coupons(9, [6, 5], [2, 3])
In this example, Nayra can buy both coupons in any order.
Hence, the procedure should return either or
.
Example 3
Consider the following call.
max_coupons(1, [2, 5, 7], [4, 3, 1])
In this example, Nayra has one token, which is not enough to buy any coupons.
Hence, the procedure should return (an empty array).
Sample Grader
Input format:
N A
P[0] T[0]
P[1] T[1]
...
P[N-1] T[N-1]
Output format:
S
R[0] R[1] ... R[S-1]
Here, is the length of the array
returned by
max_coupons
.
Attachment Package
The sample grader along with sample test cases are available here.
Comments