Problem p03170 (C++)

Buggy submission (status: Runtime Error):
// {{{
#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b)                                                           \
  for (ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b)                                                          \
  for (ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for (ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for (ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;

static inline ll mod(ll x, ll m) {
  ll y = x % m;
  return (y >= 0 ? y : y + m);
}

// }}}

int N, K;
int a[100];
bool dp[100001];

void solve() {
  dp[0] = false;
  REP(i, K + 1) {
    REP(j, N) { dp[i + a[j]] |= !dp[i]; }
  }
  cout << (dp[K] ? "First" : "Second") << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> K;
  REP(i, N) cin >> a[i];
  solve();
  return 0;
}

// vim:set foldmethod=marker:


Fixed submission:
// {{{
#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b)                                                           \
  for (ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b)                                                          \
  for (ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for (ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for (ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;

static inline ll mod(ll x, ll m) {
  ll y = x % m;
  return (y >= 0 ? y : y + m);
}

// }}}

int N, K;
int a[100];
bool dp[100001];

void solve() {
  dp[0] = false;
  REP(i, K + 1) {
    REP(j, N) {
      if (i + a[j] <= K)
        dp[i + a[j]] |= !dp[i];
    }
  }
  cout << (dp[K] ? "First" : "Second") << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> K;
  REP(i, N) cin >> a[i];
  solve();
  return 0;
}

// vim:set foldmethod=marker: