4319: 【入门】等差对(1767)

内存限制:128 MB 时间限制:1.000 S
评测方式:文本比较 命题人:
提交:4 解决:2

题目描述

给定 lns="http://www.w3.org/1998/Math/MathML"> 个数 lns="http://www.w3.org/1998/Math/MathML">,以及一个正整数 lns="http://www.w3.org/1998/Math/MathML">,问有多少对lns="http://www.w3.org/1998/Math/MathML">,,满足lns="http://www.w3.org/1998/Math/MathML">=

输入

第 lns="http://www.w3.org/1998/Math/MathML">1 行输入两个空格隔开的整数 lns="http://www.w3.org/1998/Math/MathML"> 和 lns="http://www.w3.org/1998/Math/MathML">

第 lns="http://www.w3.org/1998/Math/MathML">2 至 lns="http://www.w3.org/1998/Math/MathML">+1 行每行包含一个整数 lns="http://www.w3.org/1998/Math/MathML">

输出

输出一个数表示答案。

样例输入 复制

5 3
2
1
4
2
5

样例输出 复制

3

提示

【数据范围】

lns="http://www.w3.org/1998/Math/MathML">200000lns="http://www.w3.org/1998/Math/MathML">1,,109

#include<bits/stdc++.h>
using namespace std;
int n,c,ans=0,t;
multiset<int> s;
int a[200010];
int main(){
    cin>>n>>c;
    for(int i=1;i<=n;i++) {
    	cin>>t;
    	a[i]=t;
    	s.insert(t);
	}
	for (int i=1;i<=n;i++) {
		ans+=s.count(a[i]+c);
	}
	cout<<ans;
	return 0;
}