Skip to content

Instantly share code, notes, and snippets.

@sunho
Created May 11, 2022 23:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sunho/d5868f193220b67e807825a9eb8d1638 to your computer and use it in GitHub Desktop.
Save sunho/d5868f193220b67e807825a9eb8d1638 to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
using namespace std;
void solve() {
int N,X;
cin >> N >> X;
vector<int> A(N), B(N);
for(int i=0;i<N;i++) cin >> A[i], cin >> B[i];
vector<bool> prev(X+1);
prev[0] = true; // Takahashi was initially at x = 0
for(int t=0;t<N;t++){
vector<bool> current(X+1);
for(int x=0;x<X;x++){
if (prev[x]) { // if it was possible to reach x in the previous turn
if (x+A[t] <= X)
current[x+A[t]] = true; // mark x + A[t] as possible
if (x+B[t] <= X)
current[x+B[t]] = true; // makr x + B[t] as possible
}
}
prev = move(current);
}
if (prev[X]) {
cout << "Yes" << "\n";
} else {
cout << "No" << "\n";
}
}
int main() {
solve();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment