Skip to content

Instantly share code, notes, and snippets.

@satylogin
Created April 5, 2018 17:06
Show Gist options
  • Save satylogin/d06af84124bc61a7d5bb1f1804ee996e to your computer and use it in GitHub Desktop.
Save satylogin/d06af84124bc61a7d5bb1f1804ee996e to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long int
#define ld long double
#define pb push_back
#define mkp make_pair
#define pii pair<int, int>
#define pll pair<long long int, long long int>
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%lld", &x)
#define fi first
#define sc second
#define eps 1e-9
int A[1000], M[2][30001];
int main()
{
ios_base::sync_with_stdio(false);cout.tie(0);cin.tie(0);
int t, n, k, i, j, x, y, a, b;
cin >> t;
while (t--) {
cin >> n >> k;
int sum = 0;
for (i = 0; i < n; ++i) {
cin >> A[i];
sum += A[i];
}
x = 0;
memset(M[0], 0, sizeof(M[0]));
M[0][10000 + sum] = 1;
for (i = 0; i < n; ++i) {
y = x ^ 1;
memset(M[y], 0, sizeof(M[0]));
for (j = 0; j <= 30000; ++j) {
if (!M[x][j]) continue;
M[y][j + i + 1] = 1;
M[y][j - i - 1] = 1;
M[y][j - A[i] - A[i]] = 1;
M[y][j] = 1;
}
x ^= 1;
}
if (M[x][10000 + k]) cout << "YES" << endl;
else cout << "NO" << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment