Pair of Topics(1400分)codeforces

The next lecture in a high school requires two topics to be discussed. The i�-th topic is interesting by ai�� units for the teacher and by bi�� units for the students.

The pair of topics i� and j� (i<j�<�) is called good if ai+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 n� (2≤n≤2⋅1052≤�≤2⋅105) — the number of topics.

The second line of the input contains n� integers a1,a2,…,an�1,�2,…,�� (1≤ai≤1091≤��≤109), where ai�� is the interestingness of the i�-th topic for the teacher.

The third line of the input contains n� integers b1,b2,…,bn�1,�2,…,�� (1≤bi≤1091≤��≤109), where bi�� is the interestingness of the i�-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 3

output

Copy

7

input

Copy

4
1 3 2 4
1 3 2 4

output

Copy

0
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define PII pair<int,int>
#define IOS ios_base::sync_with_stdio(0);
int n,m,k,t;
struct node{
	int a,b,c;
}s[200086];
bool cmp(node a,node b){
	return a.c<b.c;
}
signed main(){
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> s[i].a;
	}
	for(int i=0;i<n;i++){
		cin >> s[i].b;
		s[i].c=s[i].a-s[i].b;
	}
	sort(s,s+n,cmp);
	int sum=0;
	for(int i=0;i<n;i++){
		int l=0,r=n;
		if(s[i].c<=0){
			int a=0-s[i].c;
			int p=0;
			while(l!=r){
				int mid= l+r >> 1;
				if(s[mid].c>a){
					p++;
					r=mid;
				}else{
					l=mid+1;
				}
			}
			if(p)sum+=n-l;
		}else{
			sum+=n-i-1;
		}
//		cout << l << "  ans" << endl;
	} 
	cout << sum << endl;
	return 0; 
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值