#P1989C. Two Movies

Two Movies

题面翻译

题目描述

一个公司发行了两部电影。现在有 nn 位观众,每个人都会看一部这个公司的电影。

每位观众都会对其看的电影进行评分,分数 ai,bi{101}a_i,b_i\in\{-1,0,1\}。电影的总评分是看了此电影的观众对此电影的评分总和。公司的最终得分是这两部电影的总评分的较小值。

已知这些观众对两部电影的评价,你需要给每个人推荐一部电影,使公司的最终得分最大。求这个最大值。

输入格式

第一行一个整数 tt1t1041\leqslant t \leqslant 10^4),代表输入数据组数。

接下来,对于每组数据,第一行一个整数 n n ($1 \leqslant n \leqslant 2 \times 10 ^ 5,\sum n \leqslant2\times10^5$),表示观众数。

第二行 n n 个整数 aia_i,代表每位观众对第一部电影的评价(1ai1 -1 \leqslant a_i \leqslant 1 )。

第三行 n n 个整数 bib_i,代表每位观众对第二部电影的评价(1bi1 -1 \leqslant b_i \leqslant 1 )。

输出格式

一行一个整数,代表公司最终得分的最大值。

题目描述

A movie company has released 2 2 movies. These 2 2 movies were watched by n n people. For each person, we know their attitude towards the first movie (liked it, neutral, or disliked it) and towards the second movie.

If a person is asked to leave a review for the movie, then:

  • if that person liked the movie, they will leave a positive review, and the movie's rating will increase by 1 1 ;
  • if that person disliked the movie, they will leave a negative review, and the movie's rating will decrease by 1 1 ;
  • otherwise, they will leave a neutral review, and the movie's rating will not change.

Every person will review exactly one movie — and for every person, you can choose which movie they will review.

The company's rating is the minimum of the ratings of the two movies. Your task is to calculate the maximum possible rating of the company.

输入格式

The first line contains a single integer t t ( 1t104 1 \le t \le 10^4 ) — the number of test cases.

The first line of each test case contains a single integer n n ( 1n2105 1 \le n \le 2 \cdot 10^5 ).

The second line contains n n integers a1,a2,,an a_1, a_2, \dots, a_n ( 1ai1 -1 \le a_i \le 1 ), where ai a_i is equal to 1 -1 if the first movie was disliked by the i i -th viewer; equal to 1 1 if the first movie was liked; and 0 0 if the attitude is neutral.

The third line contains n n integers b1,b2,,bn b_1, b_2, \dots, b_n ( 1bi1 -1 \le b_i \le 1 ), where bi b_i is equal to 1 -1 if the second movie was disliked by the i i -th viewer; equal to 1 1 if the second movie was liked; and 0 0 if the attitude is neutral.

Additional constraint on the input: the sum of n n over all test cases does not exceed 2105 2 \cdot 10^5 .

输出格式

For each test case, print a single integer — the maximum possible rating of the company, if for each person, choose which movie to leave a review on.

样例 #1

样例输入 #1

4
2
-1 1
-1 -1
1
-1
-1
5
0 -1 1 0 1
-1 1 0 0 1
4
-1 -1 -1 1
-1 1 1 1

样例输出 #1

0
-1
1
1