D. Pair of Topics
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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<ji<j) is called good if ai+aj>bi+bjai+aj>bi+bj (i.e. it is more interesting for the teacher).
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
Copy
5 4 8 2 6 2 4 5 4 1 3output
Copy
7input
Copy
4 1 3 2 4 1 3 2 4output
Copy
0
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll n;
scanf("%lld",&n);
ll a[n];
for(ll i=0; i<n; i++)
scanf("%lld",&a[i]);
for(ll i=0; i<n; i++)
{
ll x;
scanf("%lld",&x);
a[i]-=x;
}
sort(a,a+n);
ll l=0;
ll r=n-1;
ll sum=0;
while(l<r)
{
if(a[l]+a[r]>0)
{
sum+=r-l;
r--;
}
else l++;
}
printf("%lld\n",sum);
return 0;
}