Festival

시간 제한1초메모리 제한2048 MB

요약
A개의 토큰으로 시작해, 쿠폰 i를 사면 P[i]를 내고 남은 토큰이 T[i] (1에서 4)배가 될 때, 최대로 살 수 있는 쿠폰 수와 그 순서를 구한다.
난이도

어려움10점 중 8점

유형
그리디, 정렬, 동적 계획법, 수학
정답자
아직 제출이 없습니다

문제

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 AA tokens. There are NN coupons, numbered from 00 to N−1N-1. Nayra has to pay P\[i]P\[i] tokens (0≤i<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 (0≤i<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 X≥P\[i]X \geq P\[i]), then she will have (X−P\[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.

제한

  • 1≤N≤200,0001 \leq N \leq 200\\,000
  • 1≤A≤1091 \leq A \leq 10^{9}
  • 1≤P\[i]≤1091 \leq P\[i] \leq 10^{9} for each ii such that 0≤i<N0 \leq i < N.
  • 1≤T\[i]≤41 \leq T\[i] \leq 4 for each ii such that 0≤i<N0 \leq i < N.

예제

이 문제는 공개된 예제가 없습니다.