AT_abc296_c [ABC296C] Gap Existence 题解
Bc2_Ch1ckenPr1nce · · 题解
AT_abc296_c [ABC296C] Gap Existence 题解
题目分析
二分练习题。我们先把数组排好序,并定义一个 Yes,否则输出 No。
代码
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define qwq ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
const int N = 200020;
int n, c, a[N], ans = 0;
int solve(int ans)
{
int start = lower_bound(a + 1, a + n + 1, ans) - a;
int last = upper_bound(a + 1, a + n + 1, ans) - a;
if (start != n + 1)
return last - start;
else
return 0;
}
signed main()
{
qwq;
cin >> n >> c;
for (int i = 1; i <= n; ++ i)
{
cin >> a[i];
}
sort(a + 1, a + n + 1);
for (int i = 1; i <= n; ++ i)
{
ans += solve(a[i] + c);
}
if (ans > 0)
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
}