CF2023B Skipping
题目描述
现在已经是 3024 年了,出题的想法早就枯竭。现今的 OI 以一种修改后的个人参赛形式进行。比赛有 $n$ 道题,编号从 $1$ 到 $n$,每道题有一个分数$a_i$ 和一个参数 $b_i$。最开始,评测系统会把第 $1$ 道题丢给选手。当一个选手拿到第 $i$ 道题,他有两个选择:
- 提交,获得 $a_i$ 分
- 跳过,但他再不能去交这道题了。
接下来,评测系统会把**编号最大的符合下述条件的**题目 $j$ 丢给选手:
- 如果选手提交了 $i$ 题,那么 $j
输入格式
**此题包含多组测试数据**,第一行一个整数 $t(1\leq t\leq 10^5)$ 为测试数据组数。每组数据格式如下:
第一行一个整数 $n(1\leq n\leq 4\cdot10^5)$,表示题目总数。
第二行 $n$ 个整数 $a_1,a_2 \cdots a_n(1\leq a_i\leq 10^9)$ 表示每道题的分数。
第三行 $n$ 个整数 $b_1,b_2 \cdots b_n(1\leq b_i\leq n)$ 表示每道题的参数。
数据保证所有测试数据的 $n$ 之和不超过 $4 \cdot 10^5$。
输出格式
输出共 $t$ 行,每行输出一个整数,为小 P 最大的可能得分。
说明/提示
In the first test case, Prokhor can skip the first problem; then he will receive the problem with index $ b_1 = 2 $ . Prokhor can submit it and receive $ a_2 = 16 $ points. After that, the competition will end because Prokhor has already received all problems. Note that if Prokhor submits the first problem, he will receive $ a_1 = 15 $ points, but the competition will end immediately.
In the second test case, Prokhor can skip the first problem; then he will receive the problem with index $ b_1 = 3 $ . Prokhor can submit it and receive $ a_3 = 100 $ points. After that, Prokhor will receive the second problem, which he can skip to receive the problem with index $ b_2 = 4 $ . Prokhor can submit the fourth problem and receive another $ a_4 = 100 $ points. After that, the competition ends because Prokhor has already received all problems with indices not exceeding $ 4 $ . Thus, Prokhor will receive a total of $ 200 $ points.
In the third test case, Prokhor can submit the first problem and receive $ 100 $ points, after which the competition will end immediately.