#include <cstdio>
#include <algorithm>
using namespace std;
int n, m, Lu[1001], Zheng[10001];
bool Hui(int a){
int l = 0, r = n; //l,r分别代表头尾
while (r - l >= 1){
int i = (l + r)/2;
if (Zheng[i] == a)
return true;
else if (Zheng[i] < a)
l = i + 1;
else
r = i;
}
return false;
}
int main()
{
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++){
scanf("%d", &Lu[i]);
}
bool Yi = false;
int q = 1;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
Zheng[q++] = Lu[i] + Lu[j];
sort(Zheng + 1, Zheng + n * n + 1);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++){
if (Hui(m - Lu[i] - Lu[j]))
Yi = true;
}
if (Yi)
puts("Yes");
else
puts("No");
return 0;
}
二分法搜索
最新推荐文章于 2023-01-07 20:29:55 发布