题目

C - C

CodeForces - 1166C

The legend of the foundation of Vectorland talks of two integers xx and yy. Centuries ago, the array king placed two markers at points |x| and |y|on the number line and conquered all the land in between (including the endpoints), which he declared to be Arrayland. Many years later, the vector king placed markers at points |x−y| and |x+y|and conquered all the land in between (including the endpoints), which he declared to be Vectorland. He did so in such a way that the land of Arrayland was completely inside (including the endpoints) the land of Vectorland.

Here |z|denotes the absolute value of z.

Now, Jose is stuck on a question of his history exam: "What are the values of xx and yy?" Jose doesn't know the answer, but he believes he has narrowed the possible answers down to nn integers a1,a2,…,ana1,a2,…,an. Now, he wants to know the number of unordered pairs formed by two different elements from these nn integers such that the legend could be true if xx and yy were equal to these two values. Note that it is possible that Jose is wrong, and that no pairs could possibly make the legend true.

Input

The first line contains a single integer nn (2≤n≤2⋅1052≤n≤2⋅105)  — the number of choices.

The second line contains nn pairwise distinct integers a1,a2,…,ana1,a2,…,an (−109≤ai≤109−109≤ai≤109) — the choices Jose is considering.

Output

Print a single integer number — the number of unordered pairs {x,y}{x,y} formed by different numbers from Jose's choices that could make the legend true.

Examples

Input
3
2 5 -3
Output
2
Input
2
3 6
Output
1

Note

Consider the first sample. For the pair {2,5}{2,5}, the situation looks as follows, with the Arrayland markers at |2|=2|2|=2and |5|=5|5|=5, while the Vectorland markers are located at |2−5|=3|2−5|=3 and |2+5|=7|2+5|=7:

The legend is not true in this case, because the interval [2,3][2,3] is not conquered by Vectorland. For the pair {5,−3}{5,−3}the situation looks as follows, with Arrayland consisting of the interval [3,5][3,5] and Vectorland consisting of the interval [2,8][2,8]:

As Vectorland completely contains Arrayland, the legend is true. It can also be shown that the legend is true for the pair {2,−3}{2,−3}, for a total of two pairs.

In the second sample, the only pair is {3,6}{3,6}, and the situation looks as follows:

Note that even though Arrayland and Vectorland share 33 as endpoint, we still consider Arrayland to be completely inside of Vectorland.

题意:给出x轴上的一些坐标,从中任选两个a,b,

要求满足区间【a,b】在【abs(a-b),abs(a+b)】内,输出满足的个数

思路:由于给出的坐标无论正负都与结果无关,所以先把给出的坐标一律转换为正数,将这些数从小到大排序,假设a<b,只要满足a-b<=a ==>即 2*a>=b且a和b之间任意一个坐标都满足要求即可

#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
int s[t+5];
for(int i=0;i<t;i++)
{
cin>>s[i];
s[i]=abs(s[i]);
}
sort(s,s+t);
int ct=0;
for(int i=0;i<t;i++)
{
int l=0,r=i,st=-1;
while(l<=r)
{
int mid=(l+r)/2;
if(s[mid]*2>=s[i])
{
r=mid-1;
st=mid;
}
else
l=mid+1;
}
if(st!=-1)
{
ct+=(i-st);
}
}
cout<<ct<<endl;
}

最新文章

  1. Error:Flash Download Failed-&quot;Cortex-M3&quot;
  2. swiper超出部分出现滚动条
  3. fragment的生命周期及其各个周期方法的作用
  4. 5 Best Automation Tools for Testing Android Applications
  5. uva 10651
  6. Spring MVC Framework 实例
  7. JDK1.5新特性(五)&hellip;&hellip;Typesafe Enums
  8. Socket原理
  9. apache的斜杠问题
  10. English learning method ---学英语重中之重打通“任督二脉”
  11. Python中enumerate()的使用方法
  12. Android之EditText控件
  13. Codeforces 777C Alyona and Spreadsheet
  14. sed和awk的使用
  15. windows查看已连接WIFI密码
  16. 你不知道的JS(2)深入了解闭包
  17. SpringBoot配置Cors解决跨域请求问题
  18. JVM系列3:类加载机制
  19. ELK 性能(3) — 在 Docker 上运行高性能容错的 Elasticsearch 集群
  20. Bootstrap中的datetimepicker插件用法总结(转载)

热门文章

  1. (原创)[C#] DataTable排序扩展方法
  2. 在已有Win7/10系统电脑中加装Ubuntu18.04(安装双系统)
  3. Git工具的使用教程二
  4. ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1122)
  5. .Net Core配置Configuration源码研究
  6. 记一次线上问题 → 对 MySQL 的 ON UPDATE CURRENT_TIMESTAMP 的片面认知
  7. expression动态构成
  8. 源码解析Grpc拦截器(C#版本)
  9. String底层使用是char数组还是byte数组
  10. js复制功能代码