因为每个人的评分只可能是 -1 0 1 ,所以我们应该贪心给其推荐他给分高的电影,而对于给两个电影分相同的人,应该最后处理,
如果给分都是0,不用处理
如果给分都是1,推荐当前总得分较少的电影
如果给分都是-1,推荐当前总得分较高的电影
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include "bits/stdc++.h"
using namespace std;
#define ios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define fios ofstream("test.txt");cout.rdbuf(out.rdbuf())
#define endl "\n"
#define INF 0x3f3f3f3f
#define MINF 2147483647
#define eps 1e-6
#define PI acos(-1)
#define lowbit(x) (x & (-x))
typedef unsigned long long ULL;
typedef long long LL;
typedef pair<int, int> PII;
#define x first
#define y second
const int N = 200010;
int n;
PII a[N];
int main()
{
int T;
cin >> T;
while(T--)
{
cin >> n;
for(int i = 0; i < n; i++) cin >> a[i].x;
for(int i = 0; i < n; i++) cin >> a[i].y;
int aa = 0, bb = 0;
vector<int> b;
for(int i = 0; i < n; i++)
if(a[i].x > a[i].y) aa += a[i].x;
else if(a[i].x < a[i].y) bb += a[i].y;
else
{
//cout << a[i].x << " === " << a[i].y << endl;
b.push_back(i);
}
for(auto i : b)
{
int t = a[i].x;
if(t == 0) continue;
if(t < 0)
{
if(aa <= bb) bb--;
else if(aa > bb) aa--;
}
else if(t > 0)
{
if(aa <= bb) aa++;
else if(aa > bb) bb++;
}
}
cout << min(aa, bb) << endl;
}
return 0;
}