Problem p03170 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>

#include <algorithm>
#include <cmath>
#include <fstream>
#include <map>
#include <set>
#include <string>
#include <vector>
#define fastio                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL)
#define forl(i, a, n) for (int i = a; i < n; i++)
#define rfor(i, n, a) for (int i = n; i >= a; i--)
#define ll long long
#define ld long double
#define pb push_back
#define ld long double
#define vi vector<int>
#define vll vector<long long>
#define pi pair<int, int>
#define pll pair<long long, long long>
#define mp make_pair
#define B begin()
#define E end()
#define S size()
#define m9 1000000007
using namespace std;

/*
string fs(string str1, string str2)
{    if (str1.length() > str2.length())
        swap(str1, str2);
      string str = "";
    int n1 = str1.length(), n2 = str2.length();
    int diff = n2 - n1;
      int carry = 0;
      for (int i=n1-1; i>=0; i--)
    {

        int sum = ((str1[i]-'0') +
                   (str2[i+diff]-'0') +
                   carry);
        str.push_back(sum%10 + '0');
        carry = sum/10;
    }
      for (int i=n2-n1-1; i>=0; i--)
    {
        int sum = ((str2[i]-'0')+carry);
        str.push_back(sum%10 + '0');
        carry = sum/10;
    }
      if (carry)
        str.push_back(carry+'0');
      reverse(str.begin(), str.end());

    return str;
}*/

ll gcd(ll x, ll y) {
  if (x == 0)
    return y;
  return gcd(y % x, x);
}

/*
ll gcdextended(ll a, ll b, ll *x, ll *y)
{
    if (a == 0)
    {
        *x = 0, *y = 1;
        return b;
    }

    ll x1, y1;
    int gcd = gcdextended(b%a, a, &x1, &y1);

    *x = y1 - (b/a) * x1;
    *y = x1;

    return gcd;
}


///RELATIVE COPRIME
ll modinverse(ll a, ll m)
{
    ll x, y;
   ll g = gcdextended(a, m, &x, &y);
    if (g != 1)
return -1;
    else
    {
        ll res = (x%m + m) % m;
        return res;
    }
}
  */
ll powmod(ll x, ll y, ll m) {
  if (y == 0)
    return 1;
  ll p = powmod(x, y / 2, m) % m;
  p = (p * p) % m;
  return (y % 2 == 0) ? p : (x * p) % m;
}
/// M IS PRIME
ll modif(ll x, ll m) { return (powmod(x, m - 2, m)); }

bool fa(vll &x, vll &y) { return x[0] < y[0]; }
bool fa1(vll &x, vll &y) { return x[1] < y[1]; }
bool f1(pll &x, pll &y) { return x.second < y.second; }
bool f2(pll &x, pll &y) { return x.first > y.first; }
bool f3(ll &x, ll &y) { return x > y; }

#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
#define pin(a)                                                                 \
  for (auto x : a)                                                             \
    cout << x << " ";                                                          \
  cout << endl
#define fck(a)                                                                 \
  cout << a;                                                                   \
  exit(0)
#define vvll vector<vector<ll>>
#define A(b) b.begin(), b.end()

ll dp[3001][3001];

// include<bits/stdc++.h>

int main() {
  fastio;
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);

  ll n, k;
  cin >> n >> k;
  ll b[n];
  forl(i, 0, n) cin >> b[i];
  ll dp[k + 2];
  forl(i, 0, k + 2) dp[i] = 0;
  dp[0] = -1;
  forl(i, 1, k + 2) {
    ll ch = 0;
    for (auto x : b) {
      ll y = i - x;
      if (x < 0)
        continue;
      if (dp[y] == -1) {
        ch++;
        break;
      }
    }
    if (ch == 0) {
      dp[i] = -1;
    } else {
      dp[i] = 1;
    }
    // p2(i,ch);
  }
  // pin(dp);
  if (dp[k] == 1) {
    cout << "First";
  } else
    cout << "Second";

  return 0;
}
/*
ll n;
ll s=0;cin>>n;
ll b[n];vll t1(3,0);
forl(i,0,n){
cin>>b[i];s+=b[i];
t1[b[i]-1]++;
}
vector<map<vll,ll> > dp;
map<vll,ll>temp;
temp[t1]++;
dp.pb(temp);
//pin(t1);
ld ans=0;ld p2=temp.S,pt=0;
forl(i,0,s){
    temp.clear();
for(auto x:dp[i]){
    for(auto y:x.first)cout<<y<<" ";cout<<"\t";
forl(t,0,3){
    vll r=x.first;
    if(x.first[t]==0)continue;
    r[t]--;
    if(t>0)r[t-1]++;
    temp[r]++;pt++;
}
ld z=x.first[0]+x.first[1]+x.first[2];
ld p1=x.second;
cout<<p1<<" "<<p2<<"\t";
ld p=p1/p2;
ld f=(ld)n/z;f*=p;
cout<<n<<" "<<z<<"\t";
p1(f);
ans+=f;}
dp.pb(temp);
cout<<endl;
p2=pt;pt=0;
}
cout<<ans;

return 0;
}
*/


Fixed submission:
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>

#include <algorithm>
#include <cmath>
#include <fstream>
#include <map>
#include <set>
#include <string>
#include <vector>
#define fastio                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL)
#define forl(i, a, n) for (int i = a; i < n; i++)
#define rfor(i, n, a) for (int i = n; i >= a; i--)
#define ll long long
#define ld long double
#define pb push_back
#define ld long double
#define vi vector<int>
#define vll vector<long long>
#define pi pair<int, int>
#define pll pair<long long, long long>
#define mp make_pair
#define B begin()
#define E end()
#define S size()
#define m9 1000000007
using namespace std;

/*
string fs(string str1, string str2)
{    if (str1.length() > str2.length())
        swap(str1, str2);
      string str = "";
    int n1 = str1.length(), n2 = str2.length();
    int diff = n2 - n1;
      int carry = 0;
      for (int i=n1-1; i>=0; i--)
    {

        int sum = ((str1[i]-'0') +
                   (str2[i+diff]-'0') +
                   carry);
        str.push_back(sum%10 + '0');
        carry = sum/10;
    }
      for (int i=n2-n1-1; i>=0; i--)
    {
        int sum = ((str2[i]-'0')+carry);
        str.push_back(sum%10 + '0');
        carry = sum/10;
    }
      if (carry)
        str.push_back(carry+'0');
      reverse(str.begin(), str.end());

    return str;
}*/

ll gcd(ll x, ll y) {
  if (x == 0)
    return y;
  return gcd(y % x, x);
}

/*
ll gcdextended(ll a, ll b, ll *x, ll *y)
{
    if (a == 0)
    {
        *x = 0, *y = 1;
        return b;
    }

    ll x1, y1;
    int gcd = gcdextended(b%a, a, &x1, &y1);

    *x = y1 - (b/a) * x1;
    *y = x1;

    return gcd;
}


///RELATIVE COPRIME
ll modinverse(ll a, ll m)
{
    ll x, y;
   ll g = gcdextended(a, m, &x, &y);
    if (g != 1)
return -1;
    else
    {
        ll res = (x%m + m) % m;
        return res;
    }
}
  */
ll powmod(ll x, ll y, ll m) {
  if (y == 0)
    return 1;
  ll p = powmod(x, y / 2, m) % m;
  p = (p * p) % m;
  return (y % 2 == 0) ? p : (x * p) % m;
}
/// M IS PRIME
ll modif(ll x, ll m) { return (powmod(x, m - 2, m)); }

bool fa(vll &x, vll &y) { return x[0] < y[0]; }
bool fa1(vll &x, vll &y) { return x[1] < y[1]; }
bool f1(pll &x, pll &y) { return x.second < y.second; }
bool f2(pll &x, pll &y) { return x.first > y.first; }
bool f3(ll &x, ll &y) { return x > y; }

#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
#define pin(a)                                                                 \
  for (auto x : a)                                                             \
    cout << x << " ";                                                          \
  cout << endl
#define fck(a)                                                                 \
  cout << a;                                                                   \
  exit(0)
#define vvll vector<vector<ll>>
#define A(b) b.begin(), b.end()

ll dp[3001][3001];

// include<bits/stdc++.h>

int main() {
  fastio;
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);

  ll n, k;
  cin >> n >> k;
  ll b[n];
  forl(i, 0, n) cin >> b[i];
  ll dp[k + 2];
  forl(i, 0, k + 2) dp[i] = 0;
  dp[0] = -1;
  forl(i, 1, k + 2) {
    ll ch = 0;
    for (auto x : b) {
      ll y = i - x;
      if (y < 0)
        continue;
      if (dp[y] == -1) {
        ch++;
        break;
      }
    }
    if (ch == 0) {
      dp[i] = -1;
    } else {
      dp[i] = 1;
    }
    // p2(i,ch);
  }
  // pin(dp);
  if (dp[k] == 1) {
    cout << "First";
  } else
    cout << "Second";

  return 0;
}
/*
ll n;
ll s=0;cin>>n;
ll b[n];vll t1(3,0);
forl(i,0,n){
cin>>b[i];s+=b[i];
t1[b[i]-1]++;
}
vector<map<vll,ll> > dp;
map<vll,ll>temp;
temp[t1]++;
dp.pb(temp);
//pin(t1);
ld ans=0;ld p2=temp.S,pt=0;
forl(i,0,s){
    temp.clear();
for(auto x:dp[i]){
    for(auto y:x.first)cout<<y<<" ";cout<<"\t";
forl(t,0,3){
    vll r=x.first;
    if(x.first[t]==0)continue;
    r[t]--;
    if(t>0)r[t-1]++;
    temp[r]++;pt++;
}
ld z=x.first[0]+x.first[1]+x.first[2];
ld p1=x.second;
cout<<p1<<" "<<p2<<"\t";
ld p=p1/p2;
ld f=(ld)n/z;f*=p;
cout<<n<<" "<<z<<"\t";
p1(f);
ans+=f;}
dp.pb(temp);
cout<<endl;
p2=pt;pt=0;
}
cout<<ans;

return 0;
}
*/