CF2170C.Quotient and Remainder
普及-
通过率:0%
时间限制:2.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given two integer arrays: q1,q2,…,qn and r1,r2,…,rn, as well as an integer k.
You can perform the following operation any number of times (possibly zero):
- Choose two integers x and y such that
- 1≤y<x≤k;
- there exists an index i such that qi=⌊yx⌋ (rounded down);
- there exists an index j such that rj=xmody.
- Remove qi from the array q and rj from the array r. If there are multiple occurrences of qi in the array q, only one occurrence is removed; same for rj and the array r.
Calculate the maximum number of operations that you can perform on the given arrays q and r.
给你两个整数数组:q1,q2,…,qn 和 r1,r2,…,rn,以及一个整数 k。
你可以执行以下操作任意多次(也可以不执行):
- 选择两个整数 x 和 y,满足:
- 1≤y<x≤k;
- 存在某个下标 i,使得 qi=⌊yx⌋(向下取整);
- 存在某个下标 j,使得 rj=xmody。
- 从数组 q 中删除 qi,并从数组 r 中删除 rj。若 qi 在数组 q 中出现多次,则仅删除其中一次;同理,若 rj 在数组 r 中出现多次,则也仅删除其中一次。
请计算在给定数组 q 和 r 上最多可执行的操作次数。
输入格式
The first line contains one integer t (1≤t≤104) — the number of test cases.
The first line of each test case contains two integers n and k (1≤n≤2⋅105; 2≤k≤1018) — the size of the arrays q and r and the upper limit for x and y.
The second line of each test case contains n integers q1,q2,…,qn (1≤qi≤109) — the array q.
The third line contains n integers r1,r2,…,rn (1≤ri≤109) — the array r.
Additional constraints on the input: the sum of n over all test cases does not exceed 2⋅105.
第一行包含一个整数 t(1≤t≤104)—— 表示测试用例的数量。
每个测试用例的第一行包含两个整数 n 和 k(1≤n≤2⋅105;2≤k≤1018)—— 分别表示数组 q 和 r 的大小,以及 x 和 y 的上界。
每个测试用例的第二行包含 n 个整数 q1,q2,…,qn(1≤qi≤109)—— 即数组 q。
第三行包含 n 个整数 r1,r2,…,rn(1≤ri≤109)—— 即数组 r。
输入的额外约束:所有测试用例的 n 值之和不超过 2⋅105。
输出格式
For each test case, print one integer — the maximum number of operations that you can perform on the given arrays.
对于每个测试用例,输出一个整数——即在给定数组上最多可执行的操作次数。
输入输出样例
输入#1
3 1 100 1 27 3 10 5 6 5 7 1 7 5 42 5 4 2 2 1 9 8 9 8 100
输出#1
1 0 3
说明/提示
In the first test case, one operation can be performed: you can choose x=69 and y=42. Then ⌊4269⌋=1=q1 and 69mod42=27=r1.
In the second test case, it is impossible to perform any operations, as suitable x and y cannot be found.
In the third test case, three operations can be performed:
- x=42, y=17: ⌊1742⌋=2=q3 and 42mod17=8=r2;
- x=41, y=16: ⌊1641⌋=2=q4 and 41mod16=9=r1;
- x=20, y=12: ⌊1220⌋=1=q5 and 20mod12=8=r4;
After these operations, you'll get arrays q=[5,4] and r=[9,100], and there are no more operations you can perform.
在第一个测试用例中,可以执行一次操作:选择 x=69 和 y=42。此时 ⌊4269⌋=1=q1,且 69mod42=27=r1。
在第二个测试用例中,无法执行任何操作,因为找不到满足条件的 x 和 y。
在第三个测试用例中,可以执行三次操作:
- x=42,y=17:⌊1742⌋=2=q3,且 42mod17=8=r2;
- x=41,y=16:⌊1641⌋=2=q4,且 41mod16=9=r1;
- x=20,y=12:⌊1220⌋=1=q5,且 20mod12=8=r4;
执行完这些操作后,得到数组 q=[5,4] 和 r=[9,100],此后无法再执行任何操作。
输入解题思路,AI测评打分。不知道怎么写?