|
| 1 | +# Gambling games |
| 2 | + |
| 3 | +## Problem Description |
| 4 | + |
| 5 | +As an OIer who loves gambling, you have received a rare ticket to enter the only profitable casino in the world. There are \( n \) prize pools in the casino, and the bonus of the \( i_{th} \) prize pool is \( a_i \). Each prize pool has a parameter \( b_i \) (\( 1 \le b_i \le n \)) |
| 6 | + |
| 7 | +The casino rules are as follows:, |
| 8 | + |
| 9 | +At the beginning, players will be provided with a prize pool, and whenever they are given the \( i_{th} \) prize pool, they have two options: |
| 10 | + |
| 11 | +1. Obtain the prize money from this prize pool. |
| 12 | +2. Skip the prize money in this pool, so they will never be able to receive the prize money in this pool. |
| 13 | + |
| 14 | +Afterwards, the casino will offer players another prize pool based on the following rules |
| 15 | + |
| 16 | +If the player selects prize pool \( i \), they will choose a prize pool within the range of \( j \le i \) |
| 17 | + |
| 18 | +If the player skips prize pool \( i \), they will choose a prize pool within the range of \( j \le b_i \) |
| 19 | + |
| 20 | +Among these prize pools, it will choose the one with the highest index, which has never been given to players before (players have neither selected nor skipped it before). If there is no such prize pool, then the player's gambling is over, and their prize money is equal to the total prize money of all the selected prize pools. Especially, if players choose the first prize pool, their gambling is over. Note that players can receive a maximum of one prize pool per game. |
| 21 | + |
| 22 | +Now that you have arrived at this casino, please write a program to calculate the maximum bonus you can receive. |
| 23 | + |
| 24 | +## Input format |
| 25 | + |
| 26 | +Sure, let's translate the given problem constraints and details into LaTeX. |
| 27 | + |
| 28 | +## Problem Statement in LaTeX |
| 29 | + |
| 30 | +Each test consists of multiple test cases. |
| 31 | + |
| 32 | +The first line contains an integer \( t \) — the number of test cases. |
| 33 | + |
| 34 | +The description of the test cases is as follows: |
| 35 | + |
| 36 | +- The first line of each test case contains an integer \( n \) — the number of prize pools. |
| 37 | +- The second line of each test case contains \( n \) integers \( a_1, a_2, \ldots, a_n \) — the prize money in the prize pool. |
| 38 | +- The third line of each test case contains \( n \) integers \( b_1, b_2, \ldots, b_n \) — the parameters of the prize pool. |
| 39 | + |
| 40 | +## Output format |
| 41 | + |
| 42 | +For each test case, output an integer, representing the highest score you can obtain. |
| 43 | + |
| 44 | +## Sample input and output |
| 45 | + |
| 46 | +### Input |
| 47 | + |
| 48 | +```in |
| 49 | +4 |
| 50 | +2 |
| 51 | +15 16 |
| 52 | +2 1 |
| 53 | +5 |
| 54 | +10 10 100 100 1000 |
| 55 | +3 4 1 1 1 |
| 56 | +3 |
| 57 | +100 49 50 |
| 58 | +3 2 2 |
| 59 | +4 |
| 60 | +100 200 300 1000 |
| 61 | +2 3 4 1 |
| 62 | +``` |
| 63 | + |
| 64 | +### Output |
| 65 | + |
| 66 | +```out |
| 67 | +16 |
| 68 | +200 |
| 69 | +100 |
| 70 | +1000 |
| 71 | +``` |
| 72 | + |
| 73 | +## Constraints |
| 74 | + |
| 75 | +For all test cases: |
| 76 | + |
| 77 | +- \( 1 \leq t \leq 10^5 \) |
| 78 | +- \( 1 \leq n \leq 4 \cdot 10^5 \) |
| 79 | +- \( 1 \leq a_i \leq 10^9 \) |
0 commit comments