CF1883G1.Dances (Easy version)

普及/提高-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

This is the easy version of the problem. The only difference is that in this version m=1m = 1.

You are given two arrays of integers a1,a2,…,ana_1, a_2, \ldots, a_n and b1,b2,…,bnb_1, b_2, \ldots, b_n. Before applying any operations, you can reorder the elements of each array as you wish. Then, in one operation, you will perform both of the following actions, if the arrays are not empty:

  • Choose any element from array aa and remove it (all remaining elements are shifted to a new array aa),
  • Choose any element from array bb and remove it (all remaining elements are shifted to a new array bb).

Let kk be the final size of both arrays. You need to find the minimum number of operations required to satisfy ai<bia_i \lt b_i for all 1≤i≤k1 \leq i \leq k.

This problem was too easy, so the problem author decided to make it more challenging. You are also given a positive integer mm. Now, you need to find the sum of answers to the problem for mm pairs of arrays (c[i],b)(c[i], b), where 1≤i≤m1 \leq i \leq m. Array c[i]c[i] is obtained from aa as follows:

  • c[i]1=ic[i]_1 = i,
  • c[i]j=ajc[i]_j = a_j, for 2≤j≤n2 \leq j \leq n.

这是该问题的简单版本。唯一的区别在于本版本中 m=1m = 1。

给你两个整数数组 a1,a2,…,ana_1, a_2, \ldots, a_n 和 b1,b2,…,bnb_1, b_2, \ldots, b_n。在执行任何操作之前,你可以任意重排每个数组中的元素。然后,每次操作(当两个数组均非空时)需同时执行以下两个动作:

  • 从数组 aa 中任选一个元素并将其移除(其余元素向左移动,构成新的数组 aa);
  • 从数组 bb 中任选一个元素并将其移除(其余元素向左移动,构成新的数组 bb)。

设 kk 为最终两个数组的长度(即剩余元素个数)。你需要求出满足对所有 1≤i≤k1 \leq i \leq k 均有 ai<bia_i \lt b_i 所需的最少操作次数。

本题原本过于简单,因此出题人决定增加难度。现在你还被给定一个正整数 mm。你需要计算该问题在 mm 对数组 (c[i],b)(c[i], b)(其中 1≤i≤m1 \leq i \leq m)上的答案之和。数组 c[i]c[i] 是由 aa 按如下方式构造得到的:

  • c[i]1=ic[i]_1 = i,
  • c[i]j=ajc[i]_j = a_j,其中 2≤j≤n2 \leq j \leq n。

输入格式

Each test consists of multiple test cases. The first line contains a single integer tt (1≤t≤1041 \leq t \leq 10^4) - the number of sets of input data. This is followed by their description.

The first line of each test case contains two integers nn and mm (2≤n≤1052 \leq n \leq 10^5, m=1m = 1) - the size of arrays aa and bb and the constraints on the value of element a1a_1.

The second line of each test case contains n−1n - 1 integers a2,…,ana_2, \ldots, a_n (1≤ai≤1091 \leq a_i \leq 10^9).

The third line of each test case contains nn integers b1,b2,…,bnb_1, b_2, \ldots, b_n (1≤bi≤1091 \leq b_i \leq 10^9).

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5.

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤1041 \leq t \leq 10^4),表示输入数据组数。随后是各组数据的描述。

每个测试用例的第一行包含两个整数 nn 和 mm(2≤n≤1052 \leq n \leq 10^5,m=1m = 1),分别表示数组 aa 和 bb 的大小,以及对元素 a1a_1 的取值约束。

每个测试用例的第二行包含 n−1n - 1 个整数 a2,…,ana_2, \ldots, a_n(1≤ai≤1091 \leq a_i \leq 10^9)。

每个测试用例的第三行包含 nn 个整数 b1,b2,…,bnb_1, b_2, \ldots, b_n(1≤bi≤1091 \leq b_i \leq 10^9)。

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

输出格式

For each test case, output the total number of minimum operations for all pairs of arrays (ci,b)(c_i, b).

对于每个测试用例,输出所有数组对 (ci,b)(c_i, b) 所需的最少操作总数。

输入输出样例

  • 输入#1

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

    输出#1

    0
    1
    4
    4

说明/提示

In the first test case for the pair of arrays ([1,1],[3,2])([1, 1], [3, 2]), the answer is 00. No operations or reordering of elements are needed.

在第一组测试用例中,对于数组对 ([1,1],[3,2])([1, 1], [3, 2]),答案为 00。无需执行任何操作,也无需重新排列元素。

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

首页