题目链接:https://vjudge.net/contest/362265#problem/D
The next lecture in a high school requires two topics to be discussed. The i-th topic is interesting by aiai 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⋅105) — the number of topics.
The second line of the input contains nn integers a1,a2,…,an (1≤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,…,bn (1≤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.

Input

5
4 8 2 6 2
4 5 4 1 3

Output

7

Input

4
1 3 2 4
1 3 2 4

Output

0

题意
给定一个数n
第二行n个数,表示an
第三行n个数,表示bn
求满足i<j时,ai+aj>bi+bj的对数。

分析:
进行变形,ai-bi+aj-bj>0
用p[i]表示ai-bi
将p[i]从小到大排序。要满足p[i]+p[j]>0,其中一个肯定要大于0。假如p[i]>0,则p[j]只要大于等于-p[i]+1同时满足下标小于j即可。
代码

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
const int N=2*1e5+10;
int a[N],b[N],p[N];
int n;
int main()
{scanf("%d",&n);for(int i=1; i<=n; i++)scanf("%d",&a[i]);for(int i=1; i<=n; i++)scanf("%d",&b[i]);for(int i=1; i<=n; i++)p[i]=a[i]-b[i];sort(p+1,p+1+n);int sum=0;for(int i=1; i<=n; i++){if(p[i]<=0)continue;int pos=lower_bound(p+1,p+1+n,-p[i]+1)-p;sum+=i-pos;}printf("%d\n",sum);return 0;
}

CodeForces - 1324D Pair of Topics(思维+二分)相关推荐

  1. CodeForces - 1324D Pair of Topics(二分或双指针)

    题意:略 题记: 做法一:二分 #include<bits/stdc++.h>using namespace std; typedef long long ll; const int N= ...

  2. CodeForces - 1324D Pair of Topics (分治+排序)

    CodeForces - 1324D Pair of Topics 题目大意: 这题大意ai+aj>bi+bj全在这个式子上,就问你满足的组合有几种, 题目分析: 整理一下,得到(ai-bi)+ ...

  3. [codeforces 1324D] Pair of Topics 分而治之+排列组合

    Codeforces Round #627 (Div. 3)   比赛人数6434 [codeforces 1324C]  Frog Jumps   一直向右+边界处理 总目录详见https://bl ...

  4. Codeforces1324D Pair of Topics (思维 + 二分)

    题目链接: Pair of Topics 大致题意 给定两个数组a和b, 要求找出所有满足i < j 并且 ai + aj > bi + bj 的所有数对. 解题思路 我们不难想到先对等式 ...

  5. Codeforces 1324D Pair of Topics

    题目链接:https://codeforces.com/contest/1324/problem/D 题目描述 有两个长度为 n 的数组 A, B.问有多少对 (i,j) 满足 i < j 且 ...

  6. [Codeforces Round #627]1324D - Pair of Topics[二分]

    1324D - Pair of Topics[二分] time limit per test memory limit per test input output 2 seconds 256 mega ...

  7. CodeForces - 1324 D. Pair of Topics 思维+多解法

    CodeForces - 1324 D. Pair of Topics 原题地址: http://codeforces.com/contest/1324/problem/D 基本题意: 给你一个数组, ...

  8. cf 1324D. Pair of Topics

    D. Pair of Topics 题意:给定ab序列,问i<j且ai+aj>bi+bj的对数. 转化:ai-bi<-(aj-bj) 一开始拿到题目想着sort,但是发现i<j ...

  9. Codeforces 1324 D. Pair of Topics(二分)

    题意: 给出两组长度为 n n n 的数组 a i , b i a_i,b_i ai​,bi​,问满足 ( i < j ) a i + a j > b i + b j (i < j) ...

最新文章

  1. 程序员饭碗不保了?GPT-3 最强应用发布,动动手指就自动写代码的神器来了!...
  2. 如何下载kaggle上的数据集
  3. 2019年第十届蓝桥杯 - 省赛 - C/C++大学C组 - F. 旋转
  4. 关于Java中static关键字的用法以及从内存角度解析
  5. 果你的浏览器关闭了 java,weblogic之CVE-2018-3191漏洞分析
  6. centos 6.5 安装 phpmyadmin
  7. js基础-20-js对象赋值时的key值问题
  8. 怎么才可以使用 IPX 协议???
  9. 苹果手机如何分享wifi密码_怎样用手机改wifi密码
  10. 如何配置一台电脑。(一次解决电脑基础知识和如何选择合适电脑)
  11. 《构架师的12项修炼》读书笔记
  12. 关于深恶痛绝的file类的delete问题
  13. 机器学习核心总结-概念、线性回归、损失函数、泛化及数据集划分、特征工程、逻辑回归和分类
  14. 外国优秀网页html,200个优秀的国外设计网站推荐
  15. 华为社招机考考什么_牛客网-华为-2020届校园招聘上机考试-软件类机考-3
  16. 借助Excel批量重命名图片、文档,以及处理文件名中的空格问题(适合新手小白)
  17. 用计算机写文章 单元备课,备课写教案
  18. Acer宏基笔记本电脑捕食者Predator PH317-55原装出厂Windows10系统恢复原厂OEM系统
  19. 给我5个带”一“字的成语
  20. 【本人秃顶程序员】求求你别再写 bug 了,秃顶程序员告诉你避免空指针的 5 个案例!

热门文章

  1. [Win7安装]安装程序无法创建新的系统分区,也无法定位现有系统分区(转载)
  2. 数据库复习——SQL子查询(IN,θsome,Exists子查询)
  3. UVA - 11600 Masud Rana
  4. 外观专利申请流程及时间及费用
  5. html 重置画布坐标系,html5实现清空画布的三种方法
  6. c语言怎么弄小数点,数码管小数点
  7. jquery实现点击复制文本
  8. TCP、RPC与HTTP到底是何方神圣?!
  9. 在虚拟机安装win10系统
  10. 安卓APP设计规范(三)1080*1920设计稿对应开发尺寸