Skip to content

Instantly share code, notes, and snippets.

@nafu
Created February 17, 2013 11:34
Show Gist options
  • Save nafu/4971101 to your computer and use it in GitHub Desktop.
Save nafu/4971101 to your computer and use it in GitHub Desktop.
#include <algorithm>
#include <iostream>
using namespace std;
const int MAX_N = 100;
int n, m, k[MAX_N];
int kk[MAX_N * MAX_N];
bool binary_search(int x);
void solve();
bool binary_search(int x) {
int l = 0, r = n * n;
while (r - l >= 1) {
int i = (l + r) / 2;
if (kk[i] == x) return true;
else if (kk[i] < x) l = i + 1;
else r = i;
}
return false;
}
void solve() {
for (int c = 0; c < n; c++) {
for (int d = 0; d < n; d++) {
kk[c * n + d] = k[c] + k[d];
}
}
sort(kk, kk + n * n);
bool f = false;
for (int a = 0; a < n; a++) {
for (int b = 0; b < n; b++) {
if (binary_search(m - k[a] - k[b])) {
f = true;
}
}
}
if (f) puts("Yes");
else puts("No");
}
int main() {
scanf("%d %d", &n, &m);
for (int i = 0; i < n; i++) {
scanf("%d", &k[i]);
}
solve();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment