The next lecture in a high school requires two topics to be discussed. The ii-th topic is interesting by aiai units for the teacher and by bibi units for the students.
The pair of topics ii and jj (i
Your task is to find the number of good pairs of topics.
Input
The first line of the input contains one integer nn (2≤n≤2⋅1052≤n≤2⋅105) — the number of topics.
The second line of the input contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109), where aiai is the interestingness of the ii-th topic for the teacher.
The third line of the input contains nn integers b1,b2,…,bnb1,b2,…,bn (1≤bi≤1091≤bi≤109), where bibi is the interestingness of the ii-th topic for the students.
Output
Print one integer — the number of good pairs of topic.
Examples
Input
5
4 8 2 6 2
4 5 4 1 3
Output
7
Input
4
1 3 2 4
1 3 2 4
Output
0
这一题还是比较简单的,大概题意就是第一行给你一个数字,代表接下来两行有多少个数字,然后让你寻找下面两行里a[i]+a[j]>b[i]+b[j]的值有多少个。首先我们可以发现,他所求的就是a[i]-b[i]+(a[j]-b[j])>0,所以我们可以把两行里每一项对应的差值算出来,算出差之后,我们就可以将他们排序,我们每次都让最前面的差值与最后面的差值相加,如果>0,那么中间的项都符合要求,然后让最后的项变成-1项,若是不可行,那就让最前面的项+1,这样就可以算出来了。
下面是代码部分:
#include
#include
using namespace std;
int a[210000],b[210000],c[210000];
int main()
{
int k;
scanf("%d",&k);
int i,j,l;
for(i=0;i<k;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<k;i++)
{
scanf("%d",&b[i]);
}
for(i=0;i<k;i++)
{
c[i]=a[i]-b[i];
}
sort(c,c+k);
int n=k-1;
long long m=0;
for(i=0;i<n;)
{
if(c[i]+c[n]>0)
{
m=m+(n-i);
n=n-1;
}
else
i=i+1;
}
printf("%lld",m);
return 0;
}