-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathFriends and the Restaurant.cpp
More file actions
85 lines (72 loc) · 1.09 KB
/
Friends and the Restaurant.cpp
File metadata and controls
85 lines (72 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll max(ll a,ll b){return ((a>=b)?a:b);}
ll min(ll a,ll b){return ((a<=b)?a:b);}
ll solve()
{
int n;
cin>>n;
vector<int>v(n);
for(int i=0;i<n;i++)
{
cin>>v[i];
}
for(int i=0;i<n;i++)
{
int a;
cin>>a;
v[i]=a-v[i];
}
sort(v.begin(),v.end());
vector<int>vis(n,0);
ll pos=1e15,neg=-1,z=0,ans=0;
for(int i=0;i<n;i++)
{
if(v[i]<0)
{
neg=max(neg,i);
}
else if(v[i]>0)
{
pos=min(pos,i);
}
else
{
z++;
}
}
// for(auto a:v)cout<<a<<" ";
// cout<<endl;
while(pos<n and neg>=0)
{
if(v[neg]+v[pos]>=0)
{
vis[pos]=1;
// cout<<pos<<"=="<<neg<<endl;
ans++;
neg--;
}
pos++;
}
z=0;
for(int i=0;i<n;i++)
{
if(v[i]>=0 and vis[i]==0)z++;
}
z/=2;
ans+=z;
cout<<ans<<endl;
return 0;
}
signed main()
{
ll t,tt;
cin>>t;
tt=t;
while(t--)
{
solve();
}
return 0;
}