Logo
(追記) (追記ここまで)

34241번 - Festival 서브태스크다국어언어 제한함수 구현

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 2048 MB231010100.000%

문제

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 $A$ tokens. There are $N$ coupons, numbered from 0ドル$ to $N-1$. Nayra has to pay $P[i]$ tokens (0ドル \leq i < N$) to buy coupon $i$ (and she must have at least $P[i]$ tokens before the purchase). She can buy each coupon at most once.

Moreover, each coupon $i$ (0ドル \leq i < N$) is assigned a type, denoted by $T[i],ドル which is an integer between 1ドル$ and 4ドル,ドル inclusive. After Nayra buys coupon $i,ドル the remaining number of tokens she has gets multiplied by $T[i]$. Formally, if she has $X$ tokens at some point of the game, and buys coupon $i$ (which requires $X \geq P[i]$), then she will have $(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.

구현 상세

You should implement the following procedure.

std::vector<int> max_coupons(int A, std::vector<int> P, std::vector<int> T)
  • $A$: the initial number of tokens Nayra has.
  • $P$: an array of length $N$ specifying the prices of the coupons.
  • $T$: an array of length $N$ specifying the types of the coupons.
  • This procedure is called exactly once for each test case.

The procedure should return an array $R,ドル which specifies Nayra's purchases as follows:

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

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

입력

출력

제한

  • 1ドル \leq N \leq 200,000円$
  • 1ドル \leq A \leq 10^{9}$
  • 1ドル \leq P[i] \leq 10^{9}$ for each $i$ such that 0ドル \leq i < N$.
  • 1ドル \leq T[i] \leq 4$ for each $i$ such that 0ドル \leq i < N$.

서브태스크

번호배점제한
15

$T[i] = 1$ for each $i$ such that 0ドル \leq i < N$.

27

$N \leq 3000$; $T[i] \leq 2$ for each $i$ such that 0ドル \leq i < N$.

312

$T[i] \leq 2$ for each $i$ such that 0ドル \leq i < N$.

415

$N \leq 70$

527

Nayra can buy all $N$ coupons (in some order).

616

$(A - P[i]) \cdot T[i] < A$ for each $i$ such that 0ドル \leq i < N$.

718

No additional constraints.

힌트

예제

Example 1

Consider the following call.

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

Nayra initially has $A = 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ドル$ $(13 - 8) \cdot 3 = 15$
3ドル$ 14ドル$ 4ドル$ $(15 - 14) \cdot 4 = 4$
0ドル$ 4ドル$ 1ドル$ $(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]$.

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]$ or $[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).

샘플 그레이더

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, $S$ is the length of the array $R$ returned by max_coupons.

첨부

출처

Olympiad > International Olympiad in Informatics > IOI 2025 > Day 2 4번

제출할 수 있는 언어

C++17, C++20, C++23, C++26, C++17 (Clang), C++20 (Clang)

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /