CF2167G.Mukhammadali and the Smooth Array

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Muhammadali has an integer array a1,…,ana_1,\dots,a_n. He can change (replace) any subset of positions; changing position ii costs cic_i and replaces aia_i with any integer of his choice. The positions that he does not change must retain their original values.

After all changes, we call an index ii (1≤i<n1 \le i \lt n) a drop if the final value at position ii is strictly greater than the final value at position i+1i+1. Muhammadali wants the final array to contain no drops.

Find the minimum cost of changes required to ensure that there are no drops in the array.

穆罕默德阿里有一个整数数组 a1,…,ana_1,\dots,a_n。他可以修改(替换)任意一个位置子集;修改位置 ii 的代价为 cic_i,且会将 aia_i 替换为他任选的一个整数。未被修改的位置必须保持其原始值。

在所有修改完成后,若最终数组中位置 ii(1≤i<n1 \le i \lt n)处的值严格大于位置 i+1i+1 处的值,则称索引 ii 为一个下降点(drop)。穆罕默德阿里希望最终数组中不包含任何下降点。

求确保数组中无下降点所需的最小修改总代价。

输入格式

The first line contains an integer tt (1≤t≤50001 \le t \le 5000) — the number of test cases.

Each test case consists of three lines:

The first line contains a single integer nn (1≤n≤80001 \le n \le 8000) — the length of the arrays.

The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤1091 \le a_i \le 10^9) — the elements of the array.

The third line contains nn integers c1,c2,…,cnc_1, c_2, \dots, c_n (1≤ci≤1091 \le c_i \le 10^9) — the costs of changes.

It is guaranteed that the sum of nn across all test cases does not exceed 80008000.

第一行包含一个整数 tt(1≤t≤50001 \le t \le 5000)—— 测试用例的数量。

每个测试用例由三行组成:

第一行包含一个整数 nn(1≤n≤80001 \le n \le 8000)—— 数组的长度。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤1091 \le a_i \le 10^9)—— 数组的元素。

第三行包含 nn 个整数 c1,c2,…,cnc_1, c_2, \dots, c_n(1≤ci≤1091 \le c_i \le 10^9)—— 各位置修改操作的代价。

保证所有测试用例中 nn 的总和不超过 80008000。

输出格式

For each test case, output a single integer — the minimum possible total cost required to eliminate all drops.

对于每个测试用例,输出一个整数——消除所有水滴所需的最小总成本。

输入输出样例

  • 输入#1

    10
    1
    10
    5
    4
    1 2 2 3
    5 6 7 8
    4
    4 3 2 1
    1 1 1 1
    3
    3 1 2
    100 1 1
    5
    5 5 5 5 5
    10 1 10 1 10
    5
    1 3 2 2 4
    100 1 1 1 100
    6
    10 9 8 7 6 5
    1 100 1 100 1 100
    5
    100 1 100 100 100
    1 100 1 1 1
    4
    2 1 2 1
    5 4 3 2
    7
    1 5 3 4 2 6 7
    10 1 10 1 10 1 10

    输出#1

    0
    0
    3
    2
    0
    1
    203
    1
    6
    11

说明/提示

In the first and second examples, the array already has no drops, so no changes are needed.

In the third example, one of the optimal arrays is: [2,3,5,6][2,3,5,6]; to achieve this, all elements except the second need to be replaced, so the answer is c1+c3+c4=3c_1 + c_3 + c_4 = 3.

在第一个和第二个例子中,数组已经没有“下降”,因此无需进行任何更改。

在第三个例子中,一个最优数组为:[2,3,5,6][2,3,5,6];为得到该数组,除第二个元素外的所有元素均需被替换,因此答案为 c1+c3+c4=3c_1 + c_3 + c_4 = 3。

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

首页