CF2193D.Monster Game

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You have been gifted a new game called "Elatyh". In the game, you are given nn swords, each with its own strength. In particular, the sword numbered ii has a strength of aia_i. The game consists of nn levels, each of which features a monster.

You start at level 11 and progress further. To pass level ii and move on to level i+1i + 1, you need to defeat the monster at level ii. To defeat the monster at level ii, you need to deal it bib_i sword strikes. The swords in the game are very fragile, so they can only deal one strike before breaking. If you complete level nn or run out of swords, you can finish the game and proceed to score calculation.

Before the game, you are allowed to choose the difficulty level. If you choose difficulty xx, swords with a strength less than xx will not affect the monsters. The game score in this case is equal to xx multiplied by the number of levels completed. Your task is to choose the game difficulty in such a way as to maximize the game score.

你获得了一款名为“Elatyh”的新游戏。在游戏中,你拥有 nn 把剑,每把剑都有其独特的强度。具体而言,编号为 ii 的剑的强度为 aia_i。游戏共包含 nn 个关卡,每个关卡中都有一只怪物。

你从第 11 关开始,逐关推进。要通过第 ii 关并进入第 i+1i+1 关,你需要击败第 ii 关的怪物。要击败第 ii 关的怪物,你需要对其施加 bib_i 次剑击。游戏中的剑非常脆弱,每次只能造成一次剑击便会损坏。若你成功通关第 nn 关,或耗尽所有剑,则游戏结束,进入计分阶段。

在游戏开始前,你可以选择游戏难度。若你选择难度 xx,则所有强度小于 xx 的剑将无法对怪物造成任何影响。此时,你的游戏得分为:xx 乘以你所完成的关卡数。你的任务是选择一个合适的难度 xx,使得游戏得分最大化。

输入格式

Each test consists of several test cases. The first line contains a single integer tt (1≤t≤1041\le t\le 10^4) — the number of test cases. The following describes the test cases.

The first line of each test case contains a single integer nn (1≤n≤2⋅1051\le n\le 2 \cdot 10^5).

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤109)(1\le a_i\le 10^9).

The third line of each test case contains nn integers b1,b2,…,bnb_1, b_2, \dots, b_n (1≤bi≤n)(1\le b_i\le n).

It is guaranteed that the sum of the values of nn across all test cases does not exceed 2⋅1052 \cdot 10^5.

每个测试包含若干测试用例。第一行包含一个整数 tt(1≤t≤1041\le t\le 10^4),表示测试用例的数量。接下来描述各测试用例。

每个测试用例的第一行包含一个整数 nn(1≤n≤2⋅1051\le n\le 2 \cdot 10^5)。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤1091\le a_i\le 10^9)。

每个测试用例的第三行包含 nn 个整数 b1,b2,…,bnb_1, b_2, \dots, b_n(1≤bi≤n1\le b_i\le n)。

保证所有测试用例中 nn 的总和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, output a single integer — the maximum game score.

对于每个测试用例,输出一个整数——游戏的最高得分。

输入输出样例

  • 输入#1

    5
    3
    1 3 4
    2 1 1
    2
    2 3
    1 1
    4
    1 2 3 4
    2 2 1 1
    6
    4 4 1 4 5 4
    2 2 4 1 2 2
    10
    1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
    1 1 1 1 1 1 1 1 1 1

    输出#1

    3
    4
    3
    8
    10000000000

说明/提示

Consider the first test case. Optimal difficulty to choose is 33. If difficulty is 33, you can deal strikes with swords number 22 and 33. With 22 swords you can complete 11 level, so the game score is 3⋅1=33\cdot 1 = 3.

考虑第一个测试用例。最优选择的难度为 33。若难度为 33,则可使用编号为 22 和 33 的剑进行攻击。使用 22 把剑可以完成 11 个关卡,因此游戏得分为 3⋅1=33\cdot 1 = 3。

输入解题思路,AI测评打分。不知道怎么写?

首页