Problem p03170 (C++)

Buggy submission (status: Runtime Error):
/* _________________________________________________________________________________________________
  | | |                             Author      : Aditya Ahuja | | Date        :
  Sun,  4th Aug 2019                                    |
  |_________________________________________________________________________________________________|
*/

#include <bits/stdc++.h>
using namespace std;

// #define int long long

#define pb push_back
#define F first
#define S second
#define endl "\n"
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define req(i, a, b) for (int i = (int)b - 1; i >= a; i--)
#define all(a) (a).begin(), (a).end()
#define ret(x)                                                                 \
  {                                                                            \
    cout << x << endl;                                                         \
    return;                                                                    \
  }
#define sz(x) (int)x.size()
#define type(x) typeid(x).name()

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<vector<int>> vii;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

#ifdef LOCAL
#define wa(x) cerr << (#x) << " --- " << (x) << endl
#define pvi(v)                                                                 \
  {                                                                            \
    for (auto it : v)                                                          \
      cerr << it << " ";                                                       \
    cerr << endl;                                                              \
  }
#define line1 cerr << "---------------------------" << endl;
#else
#define wa     //
#define line1  //
#define pvi    //
#define printf //
#endif

void solve();
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout << fixed << setprecision(10);

  int t = 1;
  // cin>>t;
  while (t--)
    solve();
  return 0;
}

//___________________________________________________________________________________________________

void solve() {

  int n, k;
  cin >> n >> k;

  vi a(n);
  rep(i, 0, n) cin >> a[i];
  sort(all(a));

  vi dp(k + 1, 0);
  // dp[i] : would player 1 win if there were i stones in the pile?

  rep(i, 0, a[0]) dp[i] = 0;

  rep(i, a[0], k + 1) {
    rep(j, 0, n) {
      if (dp[i - a[j]] == 0)
        dp[i] = 1;
    }
  }

  if (dp[k])
    cout << "First" << endl;
  else
    cout << "Second" << endl;
}


Fixed submission:
/* _________________________________________________________________________________________________
  | | |                             Author      : Aditya Ahuja | | Date        :
  Sun,  4th Aug 2019                                    |
  |_________________________________________________________________________________________________|
*/

#include <bits/stdc++.h>
using namespace std;

// #define int long long

#define pb push_back
#define F first
#define S second
#define endl "\n"
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define req(i, a, b) for (int i = (int)b - 1; i >= a; i--)
#define all(a) (a).begin(), (a).end()
#define ret(x)                                                                 \
  {                                                                            \
    cout << x << endl;                                                         \
    return;                                                                    \
  }
#define sz(x) (int)x.size()
#define type(x) typeid(x).name()

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<vector<int>> vii;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

#ifdef LOCAL
#define wa(x) cerr << (#x) << " --- " << (x) << endl
#define pvi(v)                                                                 \
  {                                                                            \
    for (auto it : v)                                                          \
      cerr << it << " ";                                                       \
    cerr << endl;                                                              \
  }
#define line1 cerr << "---------------------------" << endl;
#else
#define wa     //
#define line1  //
#define pvi    //
#define printf //
#endif

void solve();
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout << fixed << setprecision(10);

  int t = 1;
  // cin>>t;
  while (t--)
    solve();
  return 0;
}

//___________________________________________________________________________________________________

void solve() {

  int n, k;
  cin >> n >> k;

  vi a(n);
  rep(i, 0, n) cin >> a[i];
  sort(all(a));

  vi dp(k + 1, 0);
  // dp[i] : would player 1 win if there were i stones in the pile?

  rep(i, 0, a[0]) dp[i] = 0;

  rep(i, a[0], k + 1) {
    rep(j, 0, n) {
      if (i - a[j] >= 0 && dp[i - a[j]] == 0)
        dp[i] = 1;
    }
  }

  if (dp[k])
    cout << "First" << endl;
  else
    cout << "Second" << endl;
}