CF1893C.Freedom of Choice
普及+/提高
通过率:0%
时间限制:3.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Let's define the anti-beauty of a multiset b1,b2,…,blen as the number of occurrences of the number len in the multiset.
You are given m multisets, where the i-th multiset contains ni distinct elements, specifically: ci,1 copies of the number ai,1, ci,2 copies of the number ai,2,…,ci,ni copies of the number ai,ni. It is guaranteed that ai,1<ai,2<…<ai,ni. You are also given numbers l1,l2,…,lm and r1,r2,…,rm such that 1≤li≤ri≤ci,1+…+ci,ni.
Let's create a multiset X, initially empty. Then, for each i from 1 to m, you must perform the following action exactly once:
- Choose some vi such that li≤vi≤ri
- Choose any vi numbers from the i-th multiset and add them to the multiset X.
You need to choose v1,…,vm and the added numbers in such a way that the resulting multiset X has the minimum possible anti-beauty.
我们定义多重集 {b1,b2,…,blen} 的**反美感(anti-beauty)**为该多重集中元素 len 出现的次数。
给定 m 个多重集,其中第 i 个多重集包含 ni 个互不相同的元素,具体为:数字 ai,1 出现 ci,1 次,数字 ai,2 出现 ci,2 次,……,数字 ai,ni 出现 ci,ni 次。保证 ai,1<ai,2<…<ai,ni。同时给定数组 l1,l2,…,lm 和 r1,r2,…,rm,满足 1≤li≤ri≤ci,1+…+ci,ni。
我们构造一个初始为空的多重集 X。然后,对每个 i 从 1 到 m,必须且仅执行一次以下操作:
- 选择某个整数 vi,满足 li≤vi≤ri;
- 从第 i 个多重集中任选 vi 个数,加入多重集 X。
你需要恰当地选择 v1,…,vm 以及每次所选的具体数字,使得最终得到的多重集 X 的反美感尽可能小。
输入格式
Each test consists of multiple test cases. The first line contains a single integer t (1≤t≤104) — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer m (1≤m≤105) — the number of given multisets.
Then, for each i from 1 to m, a data block consisting of three lines is entered.
The first line of each block contains three integers ni,li,ri (1≤ni≤105,1≤li≤ri≤ci,1+…+ci,ni≤1017) — the number of distinct numbers in the i-th multiset and the limits on the number of elements to be added to X from the i-th multiset.
The second line of the block contains ni integers ai,1,…,ai,ni (1≤ai,1<…<ai,ni≤1017) — the distinct elements of the i-th multiset.
The third line of the block contains ni integers ci,1,…,ci,ni (1≤ci,j≤1012) — the number of copies of the elements in the i-th multiset.
It is guaranteed that the sum of the values of m for all test cases does not exceed 105, and also the sum of ni for all blocks of all test cases does not exceed 105.
每个测试包含多个测试用例。第一行包含一个整数 t(1≤t≤104),表示测试用例的数量。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 m(1≤m≤105),表示给定的多重集数量。
接着,对每个 i(从 1 到 m),输入一个由三行组成的数据块。
每个数据块的第一行包含三个整数 ni,li,ri(1≤ni≤105,1≤li≤ri≤ci,1+…+ci,ni≤1017),分别表示第 i 个多重集中不同元素的个数,以及从该多重集中向集合 X 添加元素个数的上下界。
每个数据块的第二行包含 ni 个整数 ai,1,…,ai,ni(1≤ai,1<…<ai,ni≤1017),表示第 i 个多重集中的互异元素。
每个数据块的第三行包含 ni 个整数 ci,1,…,ci,ni(1≤ci,j≤1012),表示第 i 个多重集中各元素的副本数量。
保证所有测试用例中 m 的总和不超过 105,且所有测试用例中所有数据块的 ni 总和也不超过 105。
输出格式
For each test case, output the minimum possible anti-beauty of the multiset X that you can achieve.
对于每个测试用例,输出你能达到的多重集 X 的最小可能反美感值。
输入输出样例
输入#1
7 3 3 5 6 10 11 12 3 3 1 1 1 3 12 4 2 4 4 12 13 1 5 1 7 1000 1006 1000 1001 1002 1003 1004 1005 1006 147 145 143 143 143 143 142 1 2 48 50 48 50 25 25 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 2 2 1 1 1 1 1 2 1 1 1 2 1 1 2 4 8 10 11 12 13 14 3 3 3 3 2 3 4 11 12 2 2
输出#1
1 139 0 1 1 0 0
说明/提示
In the first test case, the multisets have the following form:
- 10,10,10,11,11,11,12. From this multiset, you need to select between 5 and 6 numbers.
- 12,12,12,12. From this multiset, you need to select between 1 and 3 numbers.
- 12,13,13,13,13,13. From this multiset, you need to select 4 numbers.
You can select the elements 10,11,11,11,12 from the first multiset, 12 from the second multiset, and 13,13,13,13 from the third multiset. Thus, X=10,11,11,11,12,12,13,13,13,13. The size of X is 10, the number 10 appears exactly 1 time in X, so the anti-beauty of X is 1. It can be shown that it is not possible to achieve an anti-beauty less than 1.
在第一个测试用例中,多重集合具有以下形式:
- 10,10,10,11,11,11,12。从该多重集合中,你需要选出 5 到 6 个数。
- 12,12,12,12。从该多重集合中,你需要选出 1 到 3 个数。
- 12,13,13,13,13,13。从该多重集合中,你需要选出 4 个数。
你可以从第一个多重集合中选出元素 10,11,11,11,12,从第二个多重集合中选出 12,从第三个多重集合中选出 13,13,13,13。于是,X=10,11,11,11,12,12,13,13,13,13。集合 X 的大小为 10,数字 10 在 X 中恰好出现 1 次,因此 X 的反美观度为 1。可以证明,无法得到小于 1 的反美观度。
输入解题思路,AI测评打分。不知道怎么写?