D. Pair of Topics
链接:https://codeforces.ml/contest/1324/problem/D
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
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
using namespace std;
long long n,k,ans;
long long a[200005],b[200005];
vectorc,d;
int main()
{cin>>n;for(int i=1;i<=n;i++){cin>>a[i];}for(int i=1;i<=n;i++){cin>>b[i];a[i]-=b[i];}for(int i=1;i<=n;i++){if(a[i]>0)c.push_back(a[i]);elsed.push_back(a[i]);} sort(c.begin(),c.end());sort(d.rbegin(),d.rend());int j=0;ans=0;for(int i=0;i0)j++;ans+=j;}ans+=((long long)c.size()*(c.size()-1))/2; cout<
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
