#P13538. [IOI 2025] Festival

    ID: 15414 远端评测题 1000ms 2048MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划 DP二分2025IOI交互题Special Judge

[IOI 2025] Festival

题目描述

Nayra is at a festival playing a game where the grand prize is a trip to Laguna Colorado. 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 AA tokens. There are NN coupons, numbered from 00 to N1N - 1. Nayra has to pay P[i]P[i] tokens (0i<N0 \leq i < N) to buy coupon ii (and she must have at least P[i]P[i] tokens before the purchase). She can buy each coupon at most once.

Moreover, each coupon ii (0i<N0 \leq i < N) is assigned a type, denoted by T[i]T[i], which is an integer between 11 and 44, inclusive. After Nayra buys coupon ii, the remaining number of tokens she has gets multiplied by T[i]T[i]. Formally, if she has XX tokens at some point of the game, and buys coupon ii (which requires XP[i]X \geq P[i]), then she will have (XP[i])T[i](X - P[i]) \cdot T[i] 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)
  • AA: the initial number of tokens Nayra has.
  • PP: an array of length NN specifying the prices of the coupons.
  • TT: an array of length NN specifying the types of the coupons.
  • This procedure is called exactly once for each test case.

The procedure should return an array RR, which specifies Nayra's purchases as follows:

  • The length of RR 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 R[0]R[0] first, coupon R[1]R[1] second, and so on.
  • All elements of RR must be unique.

If no coupons can be bought, RR should be an empty array.

输入格式

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, SS is the length of the array RR returned by max_coupons.

4 13
4 1
500 3
8 3
14 4
3
2 3 0
2 9
6 2
5 3
2
0 1
3 1
2 4
5 3
7 1
0


提示

Example 1

Consider the following call.

max_coupons(13, [4, 500, 8, 14], [1, 3, 3, 4])

Nayra initially has A=13A = 13 tokens. She can buy 3 coupons in the order shown below:

Coupon bought Coupon price Coupon type Number of tokens after the purchase
2 8 3 (138)3=15(13 - 8) \cdot 3 = 15
3 14 4 (1514)4=4(15 - 14) \cdot 4 = 4
0 4 1 (44)1=0(4 - 4) \cdot 1 = 0

In this example, it is not possible for Nayra to buy more than 3 coupons, and the sequence of purchases described above is the only way in which she can buy 3 of them. Hence, the procedure should return [2,3,0][2, 3, 0].

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 [0,1][0, 1] or [1,0][1, 0].

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).

Constraints

  • 1N2000001 \leq N \leq 200000
  • 1A1091 \leq A \leq 10^9
  • 1P[i]1091 \leq P[i] \leq 10^9 for each ii such that 0i<N0 \leq i < N.
  • 1T[i]41 \leq T[i] \leq 4 for each ii such that 0i<N0 \leq i < N.

Subtasks

Subtask Score Additional Constraints
1 5 T[i]=1T[i] = 1 for each ii such that 0i<N0 \leq i < N.
2 7 N3000;T[i]2N \leq 3000; T[i] \leq 2 for each ii such that 0i<N0 \leq i < N.
3 12 T[i]2T[i] \leq 2 for each ii such that 0i<N0 \leq i < N.
4 15 N70N \leq 70
5 27 Nayra can buy all NN coupons (in some order).
6 16 (AP[i])T[i]<A(A - P[i]) \cdot T[i] < A for each ii such that 0i<N0 \leq i < N.
7 18 No additional constraints.