Freedom of Choice Solution Codeforces
3 seconds
512 megabytes
standard input
standard output
Let’s define the anti-beauty of a multiset {b1,b2,…,blen}{�1,�2,…,����} 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��,1 copies of the number ai,1��,1, ci,2��,2 copies of the number ai,2,…,ci,ni��,2,…,��,�� copies of the number ai,ni��,��. It is guaranteed that ai,1<ai,2<…<ai,ni��,1<��,2<…<��,��. You are also given numbers l1,l2,…,lm�1,�2,…,�� and r1,r2,…,rm�1,�2,…,�� such that 1≤li≤ri≤ci,1+…+ci,ni1≤��≤��≤��,1+…+��,��.
Let’s create a multiset X�, initially empty. Then, for each i� from 11 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�1,…,�� and the added numbers in such a way that the resulting multiset X� has the minimum possible anti-beauty.
Each test consists of multiple test cases. The first line contains a single integer t� (1≤t≤1041≤�≤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≤1051≤�≤105) — the number of given multisets.
Then, for each i� from 11 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≤10171≤��≤105,1≤��≤��≤��,1+…+��,��≤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,…,��,�� (1≤ai,1<…<ai,ni≤10171≤��,1<…<��,��≤1017) — the distinct elements of the i�-th multiset.
The third line of the block contains ni�� integers ci,1,…,ci,ni��,1,…,��,�� (1≤ci,j≤10121≤��,�≤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 105105, and also the sum of ni�� for all blocks of all test cases does not exceed 105105.
For each test case, output the minimum possible anti-beauty of the multiset X� that you can achieve.
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}{10,10,10,11,11,11,12}. From this multiset, you need to select between 55 and 66 numbers.
- {12,12,12,12}{12,12,12,12}. From this multiset, you need to select between 11 and 33 numbers.
- {12,13,13,13,13,13}{12,13,13,13,13,13}. From this multiset, you need to select 44 numbers.
You can select the elements {10,11,11,11,12}{10,11,11,11,12} from the first multiset, {12}{12} from the second multiset, and {13,13,13,13}{13,13,13,13} from the third multiset. Thus, X={10,11,11,11,12,12,13,13,13,13}�={10,11,11,11,12,12,13,13,13,13}. The size of X� is 1010, the number 1010 appears exactly 11 time in X�, so the anti-beauty of X� is 11. It can be shown that it is not possible to achieve an anti-beauty less than 11.