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;
}
相关推荐
玖玥拾2 分钟前
C++ 数据结构 八大基础排序算法专题
数据结构·c++·算法·排序算法
Tim_1020 分钟前
【C++】017、new/delete与malloc/free的区别
java·数据结构·算法
从零开始的代码生活_1 小时前
C++ list 原理与实践:双向链表、迭代器与简化实现
开发语言·c++·后端·学习·算法·链表·list
ttod_qzstudio2 小时前
【软考算法】软件设计师下午第四题之动态规划:0-1 背包与最长公共子序列的“填表艺术“
算法·动态规划·软考
柒和远方2 小时前
LeetCode 139. 单词拆分 —— 从暴力回溯到 DP 完全背包
javascript·python·算法
从零开始的代码生活_3 小时前
C++ stack、queue 与 priority_queue:容器适配器原理与实战
开发语言·c++·后端·学习·算法
晚笙coding3 小时前
LeetCode 226. 翻转二叉树(Invert Binary Tree)
算法·leetcode·职场和发展
2zcode3 小时前
项目文档:基于MATLAB低采样率ISAR成像的快速稀疏重建算法研究
开发语言·算法·matlab
哈里沃克4 小时前
编译与链接 - 02
算法
巴糖4 小时前
Embedding了解一些
算法