Problem p03170 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define int long long int
#define mod 1000000007
#define inf 1e18
#define fo(i, y, n, inc) for (int i = y; i < n + y; i += inc)
#define cin(t)                                                                 \
  int t;                                                                       \
  cin >> t
#define w(t) while (t--)
#define nl cout << endl;
#define pb push_back
#define ft(i) (i & (-1 * i))
#define arrIn(arr, size)                                                       \
  for (int i = 0; i < size; i++) {                                             \
    cin >> arr[i];                                                             \
  }
#define arrOut(arr, size, seperater)                                           \
  for (int i = 0; i < size; i++) {                                             \
    cout << arr[i] << seperater;                                               \
  }
using namespace std;

int max(int a, int b) {
  if (a > b)
    return a;
  return b;
}

int min(int a, int b) {
  if (a < b)
    return a;
  return b;
}

void fastIO() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

int n, k;
int arr[100005];
int dp[100005];

int solve(int rem) {

  if (rem == 0)
    return 0;

  if (dp[rem] != -1)
    return dp[rem];

  int ans = 0;

  fo(i, 0, n, 1) {

    if ((rem - arr[i]) >= 0) {

      if (solve(rem - arr[i]) == 0) {
        ans = 1;
        break;
      }
    }
  }

  dp[rem] = ans;

  return ans;
}

int32_t main() {

  fastIO();
  memset(dp, -1, sizeof(dp));

  cin >> n >> k;
  fo(i, 0, n, 1) cin >> arr[i];

  if (solve(k))
    cout << "First";
  else
    cout << "Second";

  nl;

  return 0;
}

// cout << "Case #" << i << ": " << answer << endl;

Fixed submission:
#include <bits/stdc++.h>
#define int long long int
#define mod 1000000007
#define inf 1e18
#define fo(i, y, n, inc) for (int i = y; i < n + y; i += inc)
#define cin(t)                                                                 \
  int t;                                                                       \
  cin >> t
#define w(t) while (t--)
#define nl cout << endl;
#define pb push_back
#define ft(i) (i & (-1 * i))
#define arrIn(arr, size)                                                       \
  for (int i = 0; i < size; i++) {                                             \
    cin >> arr[i];                                                             \
  }
#define arrOut(arr, size, seperater)                                           \
  for (int i = 0; i < size; i++) {                                             \
    cout << arr[i] << seperater;                                               \
  }
using namespace std;

int max(int a, int b) {
  if (a > b)
    return a;
  return b;
}

int min(int a, int b) {
  if (a < b)
    return a;
  return b;
}

void fastIO() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

int n, k;
int arr[100005];
int dp[100005];

int solve(int rem) {

  if (rem == 0)
    return 0;

  if (dp[rem] != -1)
    return dp[rem];

  int ans = 0;

  fo(i, 0, n, 1) {

    if ((rem - arr[i]) >= 0) {

      if (solve(rem - arr[i]) == 0) {
        ans = 1;
        break;
      }
    }
  }

  dp[rem] = ans;

  return ans;
}

int32_t main() {

  memset(dp, -1, sizeof(dp));

  cin >> n >> k;
  fo(i, 0, n, 1) cin >> arr[i];

  if (solve(k))
    cout << "First";
  else
    cout << "Second";

  nl;

  return 0;
}

// cout << "Case #" << i << ": " << answer << endl;