记录编号 |
480640 |
评测结果 |
AAAAAAAAAAA |
题目名称 |
数对的个数 |
最终得分 |
100 |
用户昵称 |
Cirno |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.280 s |
提交时间 |
2017-12-28 14:36:36 |
内存使用 |
0.31 MiB |
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<map>
#include<iterator>
using namespace std;
std::map<int,int>lst;
map<int,int>::iterator it;
bool exist(int v)
{
if(lst.count(v))
return 1;
return 0;
}
int main()
{
freopen("dec.in","r",stdin);
freopen("dec.out","w",stdout);
int N,C;
int a;
int ans=0;
cin>>N>>C;
for(int i=0;i<N;i++)
{
cin>>a;
it=lst.find(a);
if(it==lst.end())
{
lst.insert(make_pair(a,1));
continue;
}
it->second=it->second+1;
}
for(it=lst.begin();it!=lst.end();it++)
{
//cout<<it->first<<' '<<it->second<<endl;
if(exist(it->first+C))
ans+=lst[it->first+C]*it->second;
}
cout<<ans<<endl;
return 0;
}