D. Pair of Topics

time limit per test

2 seconds

memory limit per test

256 megabytes

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 3

Output

Copy

复制代码
7

Input

Copy

复制代码
4
1 3 2 4
1 3 2 4

Output

Copy

复制代码
0

解题说明:此题是一道数学题,可以先用数列a减去数列b得到数列c,对数列c进行排序,然后统计出数列c中两者之后大于0的对数就可以了。统计数列c的时候因为已经按从小到大排序了,可以每次以头尾两个数相加计算,然后逐渐靠近得到最终值。

cpp 复制代码
#include<bits/stdc++.h>
using namespace std;

int main()
{
	int n;
	cin >> n;
	long long int count = 0;
	int a[n];
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	for (int i = 0; i < n; i++)
	{
		int x;
		cin >> x;
		a[i] = a[i] - x;
	}
	sort(a, a + n);
	int l = 0, r = n - 1;
	while (l < r)
	{
		if (a[l] + a[r] > 0)
		{
			count += r - l;
			r--;
		}
		else
		{
			l++;
		}
	}
	cout << count << '\n';
	return 0;
}
相关推荐
GIS小天15 分钟前
AI+预测3D新模型百十个定位预测+胆码预测+去和尾2025年8月25日第170弹
人工智能·算法·机器学习·彩票
PAK向日葵1 小时前
【算法导论】XM 0823 笔试题解
算法·面试
岁月栖迟1 小时前
leetcode 49. 字母异位词分组
windows·算法·leetcode
Asmalin1 小时前
【代码随想录day 21】 力扣 77. 组合
算法·leetcode·职场和发展
2501_924878596 小时前
强光干扰下漏检率↓78%!陌讯动态决策算法在智慧交通违停检测的实战优化
大数据·深度学习·算法·目标检测·视觉检测
耳总是一颗苹果7 小时前
排序---插入排序
数据结构·算法·排序算法
YLCHUP7 小时前
【联通分量】题解:P13823 「Diligent-OI R2 C」所谓伊人_连通分量_最短路_01bfs_图论_C++算法竞赛
c语言·数据结构·c++·算法·图论·广度优先·图搜索算法
花火|8 小时前
算法训练营day62 图论⑪ Floyd 算法精讲、A star算法、最短路算法总结篇
算法·图论
GuGu20248 小时前
新手刷题对内存结构与形象理解的冲突困惑
算法
汤永红8 小时前
week4-[二维数组]平面上的点
c++·算法·平面·信睡奥赛