Problem p03170 (C++)

Buggy submission (status: Runtime Error):
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <ccomplex>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#ifdef ONLINE_JUDGE
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")
#endif

// 4Head

#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(nullptr));

ll const mod = 1e9 + 7;

namespace {
ll mul(ll a, ll b) {
  ll val = a * b - (ll)((ld)a * b / mod) * mod;
  if (val < 0)
    val += mod;
  if (val >= mod)
    val -= mod;
  return val;
}

ll poww(ll a, ll b) {
  ll val = 1;
  a %= mod;
  while (b > 0) {
    if (b % 2)
      val = mul(a, val);
    a = mul(a, a);
    b >>= 1;
  }
  return val % mod;
}

ll inv(ll a) { return poww(a, mod - 2); }
} // namespace

int const maxn = 3e5 + 5;

int dp[maxn];

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < a[0]; i++) {
    dp[i] = 0;
  }
  for (int i = a[0]; i < maxn; i++) {
    bool can = false;
    for (int x : a) {
      if (dp[i - x] == 0)
        can = true;
    }
    dp[i] = can;
  }

  cout << (dp[k] == 1 ? "First" : "Second") << endl;

  return 0;
}

/*
5
2 6 15 5 10

4
2 6 15 5

*/

Fixed submission:
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <ccomplex>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#ifdef ONLINE_JUDGE
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")
#endif

// 4Head

#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(nullptr));

ll const mod = 1e9 + 7;

namespace {
ll mul(ll a, ll b) {
  ll val = a * b - (ll)((ld)a * b / mod) * mod;
  if (val < 0)
    val += mod;
  if (val >= mod)
    val -= mod;
  return val;
}

ll poww(ll a, ll b) {
  ll val = 1;
  a %= mod;
  while (b > 0) {
    if (b % 2)
      val = mul(a, val);
    a = mul(a, a);
    b >>= 1;
  }
  return val % mod;
}

ll inv(ll a) { return poww(a, mod - 2); }
} // namespace

int const maxn = 3e5 + 5;

int dp[maxn];

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < a[0]; i++) {
    dp[i] = 0;
  }
  for (int i = a[0]; i < maxn; i++) {
    bool can = false;
    for (int x : a) {
      if (x > i)
        break;
      if (dp[i - x] == 0)
        can = true;
    }
    dp[i] = can;
  }

  cout << (dp[k] == 1 ? "First" : "Second") << endl;

  return 0;
}

/*
5
2 6 15 5 10

4
2 6 15 5

*/