Problem:


Score : 100 points

Problem Statement

There is a set A = \{ a_1, a_2, \ldots, a_N \} consisting of N positive integers.
Taro and Jiro will play the following game against each other.

Initially, we have a pile consisting of K stones.
The two players perform the following operation alternately, starting from Taro:

Choose an element x in A, and remove exactly x stones from the pile.

A player loses when he becomes unable to play.
Assuming that both players play optimally, determine the winner.

Constraints

All values in input are integers.

1 \leq N \leq 100

1 \leq K \leq 10^5

1 \leq a_1 < a_2 < \cdots < a_N \leq K

Input

Input is given from Standard Input in the following format:

N K
a_1 a_2 \ldots a_N

Output

If Taro will win, print First; if Jiro will win, print Second.

Sample Input 1

2 4
2 3

Sample Output 1

First

If Taro removes three stones, Jiro cannot make a move.
Thus, Taro wins.

Sample Input 2

2 5
2 3

Sample Output 2

Second

Whatever Taro does in his operation, Jiro wins, as follows:

If Taro removes two stones, Jiro can remove three stones to make Taro unable to make a move.

If Taro removes three stones, Jiro can remove two stones to make Taro unable to make a move.

Sample Input 3

2 7
2 3

Sample Output 3

First

Taro should remove two stones. Then, whatever Jiro does in his operation, Taro wins, as follows:

If Jiro removes two stones, Taro can remove three stones to make Jiro unable to make a move.

If Jiro removes three stones, Taro can remove two stones to make Jiro unable to make a move.

Sample Input 4

3 20
1 2 3

Sample Output 4

Second

Sample Input 5

3 21
1 2 3

Sample Output 5

First

Sample Input 6

1 100000
1

Sample Output 6

Second



Sample input:
2 4
2 3


Sample output:
First

Submission status: Accepted

Solution code:
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue
#import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)



        
def main(): #startline--------------------------------------------
    n,k = map(int,input().split())
    a = list(map(int,input().split()))
    dp = [-1]*(k+1)
    for i in range(k+1):
        dp[i] = 0
        for j in range(n):
            if a[j] > i:
                break
            if 1 ^ dp[i-a[j]]:
                dp[i] = 1
                break

    print("First" if dp[k] else "Second")
if __name__ == "__main__":
    main() #endline===============================================

Submission status: Accepted

Solution code:
#K

N,K=map(int,input().split())
a=list(map(int,input().split()))

#先手が勝つ：1，負ける0
dp=[0]*(K+1)

for i in range(N):
    dp[a[i]]=1
    
for i in range(K+1):
    if dp[i]==0:
        for j in range(N):#a[j]だけ引いたところに0があれば先手は勝てる
            if i-a[j]>=0:
                if dp[i-a[j]]==0:
                    dp[i]=1
                    break
                    
if dp[-1]==1:
    print("First")
else:
    print("Second")

Submission status: Accepted

Solution code:
def main():
  n,k=map(int,input().split())
  num=[int(i) for i in input().split()]
  
  dp=[0]*(k+1)
  for i in range(k):
    flag=False
    for j in range(n):
      if i+1-num[j]>=0:
        if  dp[i+1-num[j]]==0:
          flag=True
          break
    if flag:
      dp[i+1]=1
    else:
      continue
  if dp[k]:
    print('First')
  else:
    print('Second')          
if __name__=='__main__':
  main()

Submission status: Accepted

Solution code:
# https://kyopro-friends.hatenablog.com/entry/2019/01/12/231000

def main():
    import sys
    readline = sys.stdin.readline

    n, k = map(int, readline().rstrip().split())
    *a, = sorted(map(int, readline().split()))

    dp = [False] * (k + 1)
    dp[0] = False
    # dp[手番開始時の石の個数]:=勝敗

    for i in range(1, k + 1):
        for x in a:
            if x > i: break
            if not dp[i - x]:
                dp[i] = True
                break

    print('First' if dp[k] else 'Second')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
dp = [False] * (2 * K + 1)

for i in range(K, 0, -1):
  if all([not dp[i+j] for j in A]):
    dp[i] = True

print("First" if any([dp[i] for i in A]) else "Second")

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,K = MI()
    A = LI()
    can_win = [False]*(K+1) #can_win[i]:山にi個ある時に勝てるか

    for i in range(1,K+1):
        for a in A:
            if a<=i:
                if not can_win[i-a]: #a個取ったら相手が勝てなくなるなら勝てるということ
                    can_win[i] = True
                    break
    print(("Second","First")[can_win[-1]])

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
aa = list(map(int,input().split()))

dp = [-1]*(k+1)

for i in range(1,k+1):
  for j in range(n):
    if i >= aa[j]:
      dp[i] = max(dp[i],-dp[i-aa[j]])

if dp[k]>0:
  print('First')  
else:
  print('Second')

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
dp = [False for i in range(K+1)]
for i in range(1,K+1):
    for j in range(N):
        if i-A[j] >= 0:
            dp[i] |= not dp[i-A[j]]
if dp[-1]:
    print('First')
else:
    print('Second')

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
A=list(map(int,input().split()))
dp=[False] * (k+1)
for i in range(k):
    for j in range(n):
        if dp[i]==False and i+A[j]<=k:
            dp[i+A[j]]=True
print('First' if dp[k] else 'Second')

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
A=sorted(map(int,input().split()))
dp=[0]*(k+1)
dp[1]=0
for i in range(k):
    if dp[i]==0:
        for a in A:
            if i+a<=k:
                dp[i+a]=1
print("Second"if dp[k]==0 else"First")

Submission status: Accepted

Solution code:
def examA():
    N = I()
    H = LI()
    dp = [inf]*(N)
    dp[0] = 0
    for i in range(N-1):
        dp[i+1] = min(dp[i+1],dp[i]+abs(H[i+1]-H[i]))
        if i<N-2:
            dp[i + 2] = min(dp[i + 2], dp[i]+abs(H[i + 2] - H[i]))
    ans = dp[-1]
    print(ans)
    return

def examB():
    N, K = LI()
    H = LI()
    dp = [inf]*N
    dp[0] = 0
    for i in range(N):
        for k in range(1,K+1):
            if i+k>=N:
                break
            if dp[i+k]>dp[i]+abs(H[i+k]-H[i]):
                dp[i+k] = dp[i]+abs(H[i+k]-H[i])
    ans = dp[-1]
    print(ans)
    return

def examC():
    N = I()
    A = [0]*N; B = [0]*N; C = [0]*N
    for i in range(N):
        A[i],B[i],C[i] = LI()
    dp = [[0]*3 for _ in range(N+1)]
    for i in range(N):
        dp[i+1][0] = max(dp[i][1],dp[i][2]) + A[i]
        dp[i + 1][1] = max(dp[i][0], dp[i][2]) + B[i]
        dp[i + 1][2] = max(dp[i][1], dp[i][0]) + C[i]
    ans = max(dp[N])
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    # LCS
    S = SI(); N = len(S)
    T = SI(); M = len(T)
    dp = [[0] * (M + 1) for _ in range(N + 1)]
    for i in range(N):
        for j in range(M):
            if S[i] == T[j]:
                dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1)
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i+1][j], dp[i][j+1])

    i = N; j = M
    ans = []
    while i > 0 and j > 0:
        if dp[i][j] == dp[i-1][j]:
            i -= 1
        elif dp[i][j] == dp[i][j-1]:
            j -= 1
        else:
            ans.append(S[i-1])
            i -= 1
            j -= 1
    print("".join(ans[::-1]))
    return

def examG():
    # http://zehnpaard.hatenablog.com/entry/2018/06/26/201512
    # トポロジカルソート
    def topological_sort(n,outs,ins):
        q = deque(v1 for v1 in range(n) if ins[v1] == 0)
        res = []
        while q:
            v1 = q.popleft()
            res.append(v1)
            for v2 in outs[v1]:
                ins[v2] -= 1
                if ins[v2] == 0:
                    q.append(v2)
        return res
    N, M = LI()
    V = [[]for _ in range(N)]
    start = [0]*N
    for _ in range(M):
        x,y = LI()
        x -= 1; y -= 1
        V[x].append(y)
        start[y] += 1
    Order = topological_sort(N, V, start)
#    print(Order)
    dp = [0]*N
    for i in Order:
        for v in V[i]:
            dp[v] = max(dp[v],dp[i]+1)
    ans = max(dp)
    print(ans)
    return

def examH():
    H, W = LI()
    A = [SI() for _ in range(H)]
    dp = [[0]*W for _ in range(H)]
    dp[0][0] = 1
    for i in range(H):
        for j in range(W):
            if A[i][j]=="#":
                continue
            dp[i][j] %=mod
            if i+1<H and dp[i+1][j]!="#":
                dp[i+1][j] +=dp[i][j]
            if j+1<W and dp[i][j+1]!="#":
                dp[i][j+1] +=dp[i][j]
    ans = dp[-1][-1]
    print(ans)
    return

def examI():
    N = I()
    P = LFI()
    dp = [[0]*(N+1) for _ in range(N+1)]
    dp[0][0] = 1
    for i in range(N):
        for j in range(i+1):
            dp[i+1][j+1] += dp[i][j]*P[i]
            dp[i+1][j] += dp[i][j]*(1-P[i])
    ans = 0
    for v in dp[N][(1+N//2):]:
        ans += v
    print(ans)
    return

def examJ():
    N = I()
    A = LI()
    dp = [[[0]*(N+1) for _ in range(N+1)]for _ in range(N+1)]
    S = Counter(A)
    print(S)
    dp[S[1]][S[2]][S[3]] = 0
    que = deque()
    que.append((S[1],S[2],S[3]))
    used = defaultdict(set)
    while(que):
        n1,n2,n3 = que.popleft()
        if used[(n1,n2,n3)]:
            continue
        used[(n1,n2,n3)] = True
        now = n1+n2+n3
        if n1>0:
            dp[n1-1][n2][n3] += dp[n1][n2][n3] + N/now * n1/now
            que.append((n1-1, n2, n3))
        if n2>0:
            dp[n1+1][n2-1][n3] += dp[n1][n2][n3] + N/now * n2/now
            que.append((n1+1,n2-1,n3))
        if n3>0:
            dp[n1][n2+1][n3-1] += dp[n1][n2][n3] + N/now * n3/now
            que.append((n1,n2+1,n3-1))
#    print(dp)
    ans = dp[0][0][0]
    print(ans)
    return

def examK():
    N, K = LI()
    A = LI()
    dp = [-1]*(K+1)
    for i in range(1,K+1):
        flag = False
        for a in A:
            if a>i:
                break
            if dp[i-a]==-1:
                flag = True
                break
        if flag:
            dp[i] = 1
#    print(dp)
    ans = dp[K]
    if ans==1:
        print("First")
    else:
        print("Second")
    return

def examM():
    N, K = LI()
    A = LI()
    dp = [[0]*(K+1) for _ in range(N+1)]
    dp[0][0] = 1
    for i in range(N):
        cum = [0]*(K+1)
        cum[0] = dp[i][0]
        for c in range(K):
            cum[c+1] = cum[c] + dp[i][c+1]
        for j in range(K+1):
            if j<=A[i]:
                dp[i+1][j] = cum[j]
            else:
                dp[i+1][j] = cum[j] - cum[j-A[i]-1]
            dp[i+1][j] %=mod
#    print(dp)
    ans = dp[N][K]%mod
    print(ans)
    return

def examP():
    def dfs_dp(n,s,fords):
        W = 1; B = 1
        for v in fords[s]:
            W *= sum(dfs_dp(n, v, fords)[v])
            B *= dfs_dp(n, v, fords)[v][0]
        return (W,B)
    N = I()
    V = [[]for _ in range(N)]
    for _ in range(N-1):
        x,y = LI()
        x -=1; y -=1
        V[x].append(y)
        V[y].append(x)
    ans = dfs_dp(N,0,V)
    print(ans)
    print("nemui")
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LFI(): return list(map(float,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examK()

"""

"""

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
al = list(map(int,input().split()))

dp = [0 for i in range(k+1)]

for i in range(k+1):
    for a in al:
        if a <= i:
            if dp[i-a] == 0:
                dp[i] = 1


if dp[-1] % 2 == 0:
    print("Second")
else:
    print("First")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Jan 19 20:52:57 2020

@author: over-
"""


N, K=map(int,input().split())
a=input().split()
a=[int(i) for i in a]
a.sort()

dp=[0]*(K+1)
dp[0]=1

for i in range(1,K+1):
    dp[i]=1
    for j in a:
        if j > i: break
        if dp[i-j]==1: 
            dp[i]=0
            break
          
            

    
if dp[-1]==0:
    print('First')
else:
    print('Second')

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
dp = [False]*(K+1)
for i in range(1,K+1):
    for a in A:
        if i-a >= 0 and dp[i-a] == False:
            dp[i] = True
            break
print("First" if dp[-1] else "Second")

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
max_a = A[-1]

dp = [0] * (K+1)

for a in A:
    dp[a] = 1

for i in range(1, K + 1):
    bl = False
    for a in A:
        if i - a < 0:
            break
        if dp[i - a] == 0:
            bl = True
            break
    dp[i] = 1 if bl else 0


ans = "First" if dp[K] else "Second"
print(ans)

Submission status: Accepted

Solution code:
def solve(N, K, cards):
  min_elem = cards[0]

  # dp[i] == True: Current player will win if i stones left
  dp = [False for _ in range(K + 1)]
  for i in range(min_elem):
    dp[i] = False

  for k in range(1, K + 1):
    for c in cards:
      if c > k:
        break
      if k - c >= 0 and dp[k - c] == False:
        dp[k] = True

  print("First" if dp[K] else "Second")

  
def iln(): return list(map(int, input().split()))


N, K = iln()
cards = iln()
solve(N, K, cards)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

N,K   = map(int,input().split())
lst_a = list(map(int, input().split()))

dp= [-1 for i in range(K+1)]
dp[0] = 0
for i in range(1,K+1):
	check = False
	for j in lst_a:
		if(i-j>=0):
			if (dp[i-j] == 0):
				check = True
	if(check): dp[i]= 1
	else : dp[i]= 0

if(dp[K]==1):
	print("First")
else:
	print("Second")

Submission status: Accepted

Solution code:
n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
dp = [0 for i in range(k+1)]
dp[0]=2
for i in range(1,k+1):
    l=0
    for j in range(n):
        if dp[i-a[j]]==2:
            l=l+1
            break
    if l==1:
        dp[i]=1
    else:
        dp[i]=2
if dp[k]==1:
    print("First")
else:
    print("Second")

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
*a, = map(int, input().split())

# dp[i]=石の数がi個の場合の手番の人の勝ち負け
dp = [False]*(K+1)

for i in range(1, K+1):
    for j in range(N):
        # 遷移先にFalseがあればTrueにする
        # TrueになったらFalseにはならないため、orで入れる
        if i >= a[j]:
            dp[i] |= not dp[i-a[j]]

print("First" if dp[K] else "Second")

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
m = A[0]

dp = [False] * (K+1)

for k in range(m, K+1):
  for a in A:
    if k - a < 0:
      continue
    if not dp[k-a]:
      dp[k] = True
      break

if dp[K]:
  print('First')
else:
  print('Second')

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
As = list(map(int, input().split()))
d = [True]+[True]*K
for i in range(1, K+1):
    for a in As:
        if i-a<0:
            continue
        if d[i-a]:
            d[i] = False
            break

if d[-1]:
    print("Second")
else:
    print("First")

Submission status: Accepted

Solution code:
def stones(k, moves):
    winnable = [False] * (k + 1)
    for i in range(1, k+1):
        winnable[i] = not all(winnable[i - j] for j in moves if j <= i)
    return ["Second", "First"][winnable[k]]

def main():
    n, k = [int(x) for x in input().split()]
    moves = [int(x) for x in input().split()]
    return stones(k, moves)

print(main())

Submission status: Accepted

Solution code:
import math
import sys

N,K = list(map(int,input().split(" ")))
As = list(map(int,input().split(" ")))

dp = [False] * (K + 1)
for i in range(K + 1):
    for a in As:
        if i + a <= K:
            dp[i + a] |= (not dp[i])
        else:
            break
ans = "First" if dp[K] else "Second"
print(ans)

Submission status: Accepted

Solution code:
import math
import sys

N,K = list(map(int,input().split(" ")))
As = list(map(int,input().split(" ")))

dp = [False] * (K + 1)
for i in range(K + 1):
    for a in As:
        if i + a <= K:
            dp[i + a] |= (not dp[i])
ans = "First" if dp[K] else "Second"
print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
As = list(map(int, input().split()))

# 1  : First
# -1 : Second

import pdb

tmp = [0 for _ in range(N)]
tmp_win = [0 for _ in range(N)]
win = [0 for _ in range(K+1)]

flg = 0

# pdb.set_trace()

for stones in range(K+1):
  for i in range(N):
    # 残数stonesの時、先行の操作の結果なり得る残数の場合をすべて求める
    tmp[i] = stones - As[i]
    if tmp[i] == 0:
      # 残数が0になるものがあればその操作を行うことで先行の勝ちが確定
      flg = 1

  if flg == 1:
    # 先行の勝ち
    win[stones] = 1
    flg = 0
    continue

  if max(tmp) < 0:
    # 残数stonesの時からどの操作を行っても残数が負になる場合は後攻の勝ち
    win[stones] = -1
    continue

  # 上記で勝ち負けがわからない場合、
  win[stones] = -1    # 一旦負けで仮置き
  for i in range(N):
    # 次の操作でとりうる個数に対しての勝ち負けを見る
    tmp_win = win[tmp[i]]
    if tmp_win == -1:
      # 次の操作後に残る数で後攻が勝つのであれば、
      # その直前の状態で先行の勝ち筋が存在
      win[stones] = 1
      break

# print(win)
winner = ['', 'First', 'Second']
print(winner[win[K]])
  # if max(tmp) < min(As):
  #   # 残数stonesの時、
  #   win[stones] = 1:
  #   continue

Submission status: Accepted

Solution code:
def wczytaj_liste(): 
    wczytana_lista = input()
    lista_znakow = wczytana_lista.split()
    ostateczna_lista = []
    for element in lista_znakow:
        ostateczna_lista.append(int(element))
    return ostateczna_lista


def kamienie_niemilosci(): 
    N, K = wczytaj_liste()
    A = wczytaj_liste()
    win = {1:'First', 2:'Second'}
    odp = []
    for i in range(K+1):
        if i < A[0]:
            odp.append(2)
        else:
            czy_istnieje = False
            for male_a in A: 
                if i - male_a >= 0 and odp[i-male_a] == 2: 
                    czy_istnieje = True
            if czy_istnieje: 
                odp.append(1)
            else: 
                odp.append(2)
    print(win[odp[K]])
    
kamienie_niemilosci()

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
a = [int(x) for x in input().split()]

dp = []

for i in range(k+1):
    First_win = any(map(lambda x: not dp[i-x] if i-x >= 0 else False, a))
    dp.append(First_win)

print('First' if dp[k] else 'Second')

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
a = [int(x) for x in input().split()]

dp = [-1 for _ in range(k+1)]

for i in range(min(a)):
    dp[i] = 1

for i in range(k+1):
    tmp = 0
    for x in a:
        if i-x < 0:
            continue
        else:
            tmp += dp[i-x]
    if tmp > 0:
        dp[i] = 0
    else:
        dp[i] = 1

print('First' if dp[k] == 0 else 'Second')

Submission status: Accepted

Solution code:
n,k = map(int, input().split())
a = list(map(int, input().split()))

dp = [0]*(k+1)

for i in range(a[0]):
    dp[i] = 2

for i in range(a[0],k+1):
    for j in a:
        if(j > i):
            dp[i] = 2
            break
        if(dp[(i-j)]==2):
            dp[i] = 1
            break
        dp[i] = 2

if(dp[k] == 1):
    print('First')
else:
    print('Second')

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, K: int, a: "List[int]"):

    # 石k個で勝利するプレイヤー0 or 1
    dp = [1]*(K+1)
    dp[0] = 1
    for k in range(1, K+1):
        dp[k] = 1
        for i in range(N):
            if k-a[i] >= 0 and dp[k-a[i]] == 1:
                dp[k] = 0
    print("First" if dp[K] == 0 else "Second")

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, a)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#import sys
#input = sys.stdin.readline
def main():
    N, K = map( int ,input().split())
    A = list( map(int, input().split()))
    dp = [False]*(K+1)
    for i in range(A[0],K+1):
        for a in A:
            if a > i:
                break
            dp[i] |= not dp[i-a]
    if dp[K]:
        print("First")
    else:
        print("Second")
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#import sys
#input = sys.stdin.readline
def main():
    N, K = map( int ,input().split())
    A = list( map(int, input().split()))
    dp = [False]*(K+1)
    for i in range(A[0],K+1):
        for a in A:
            if a > i:
                break
            dp[i] |= not dp[i-a]
    if dp[K]:
        print("First")
    else:
        print("Second")
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#import sys
#input = sys.stdin.readline
def main():
    N, K = map( int, input().split())
    A = list( map( int, input().split()))
    dp = [[None]*2 for _ in range(K+1)]
    for i in range(A[0]):
        dp[i][0] = False
        dp[i][1] = True
    for k in range(A[0], K+1):
        win = False
        for a in A:
            if a <= k:
                if dp[k-a][1]:
                    win = True
                    break
        dp[k][0] = win
        win = True
        for a in A:
            if a <= k:
                if not dp[k-a][0]:
                    win = False
                    break
        dp[k][1] = win
    if dp[K][0]:
        print("First")
    else:
        print("Second")

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
arr = [int(x) for x in input().split()]

dp = [False] * (k+1)

for stones in range(k+1):
    for num in arr:
        # If i'm choosing num stones and dp[stones - num] is false then opponent will loose
        if stones >= num and not dp[stones-num]:
            dp[stones] = True

ans = "First" if dp[k] else "Second"
print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))

dp = [False]*(k+1)
for j in range(1,k+1):
    tmp = False
    for i in range(n):
        if a[i] > j:
            continue
        if not dp[j-a[i]]:
            tmp = True
    dp[j] = tmp

if dp[-1]:
    print("First")
else:
    print("Second")

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N,K = map(int,input().split())
A = [int(i) for i in input().split()]

# dp[i]: 石の個数が残りi個の局面での勝敗
dp = [False] * (K+1)

# 初期条件
dp[0] = False

for i in range(K+1):
    for a in A:
        if i+a > K:
            continue
        dp[i+a] |= not dp[i]

if dp[-1]:
    print("First")
else:
    print("Second")

Submission status: Accepted

Solution code:
def main():
	n, k, *a = map(int, open(0).read().split())
	g = [0] * (k + 1)
	for i in range(min(a), k + 1):
		s = set(g[i - x] for x in a if i >= x)
		r = 0
		while r in s:
			r += 1
		g[i] = r
	print("First" if g[-1] else "Second")
	
if __name__=="__main__":
	main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-


def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    dp = [0 for _ in range(k + 1)]  # Firstが到達できるかどうかを管理

    # 石を順番に積み上げる(石を取り去る，を言い換え)
    # See:
    # https://atcoder.jp/contests/dp/submissions/3956066
    for i in range(k):
        # 既にFirstが到達可能な場合
        if dp[i]:
            continue

        # ある個数から，集合Aをすべて試す
        for ai in a:
            # k個より大きくなったら，計算を打ち切る
            # 範囲外参照を防ぐため
            if i + ai > k:
                break

            # 更新
            dp[i + ai] = 1

    if dp[-1] == 1:
        print('First')
    else:
        print('Second')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-


def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    dp = [0 for _ in range(k + 1)]

    # See:
    # https://atcoder.jp/contests/dp/submissions/3956066
    for i in range(k):
        if dp[i]:
            continue

        for ai in a:
            if i + ai > k:
                break

            dp[i + ai] = 1

    if dp[-1] == 1:
        print('First')
    else:
        print('Second')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,K = map(int, input().split())
A = [int(a) for a in input().split()]

dp = [False]*(K+1)

for i in range(K+1):
    f = False
    for j in range(N):
        if A[j] > i:
            break
        if dp[i-A[j]]:
            continue
        f = True
    dp[i] = f
    
if dp[K]:
    ans = "First"
else:
    ans = "Second"
        
print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
a = [int(c) for c in input().split()]


dp = [False] * (K+1)
for k in range(K+1):
    for ai in a:
        if k >= ai:
            dp[k] = dp[k] or (not dp[k-ai])

print('First' if dp[k] else 'Second')

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
dp = [0 for _ in range(K+1)]
for i in range(K+1):
    if i<A[0]:
        dp[i] = 0
    else:
        dp[i] = not dp[i-A[0]]
        for j in range(1,N):
            if i>=A[j]:
                dp[i] = dp[i] or not dp[i-A[j]]
if dp[K]==True:
    print("First")
else:
    print("Second")

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))

dp = [0 for _ in range(K+1)]

for i in range(K+1):
    for j in range(N):
        if i-A[j] >= 0:
            dp[i] |= not dp[i-A[j]]
            
if dp[K]:
    print('First')
else:
    print('Second')

Submission status: Accepted

Solution code:
n, k = [int(x) for x in input().strip().split()]
a = [int(x) for x in input().strip().split()]
a.sort()
dp = {} #determines whether dp[k] is a winning position or not
for i in range(k+1):
    dp[i] = False

for e in a:
    dp[e] = True

for i in range(a[0],k+1):
    for j in a:
        if i-j in dp:
            dp[i] = dp[i] or not(dp[i-j]) #if previous is true this is false
                                          #taken or to get best case of all optimality

if dp[k] is False:
    print('Second')
else:
    print('First')

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
#dp[i] - TRUE if the first player wins if there are i stones remaining
dp = [False] * (k + 1)
for stones in range(k + 1):
    for x in a:
        if stones >= x and not dp[stones - x]:
            dp[stones] = True
print('First' if dp[k] else 'Second')

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
arr = list(map(int, input().split()))
dp = [0] * (k + 1)
dp[0] = 0
for i in range(k + 1):
    for j in arr:
        if i >= j and not dp[i - j]:
            dp[i] = 1
print("First" if dp[-1] else "Second")

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
S=[int(i) for i in input().split()]

dp=[False]*(K+1)

for i in range(K+1):
    #print(dp)
    for s in S:
        f=False
        if i-s<0:
            break
        if not dp[i-s]:
            dp[i]=True
            break
#print(dp)
if dp[-1]:
    print("First")
else:
    print("Second")

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))

dp = [0] * (K+1)
for i in range(K):
    for a in A:
        if dp[i] == 0:
            if i + a <= K:
                dp[i+a] = 1

if dp[-1] == 0:
    print('Second')
else:
    print('First')

Submission status: Accepted

Solution code:
def p_k():
    n, k = map(int, input().split())
    *a, = map(int, input().split())

    dp = [False] * (k + 1)
    for i in range(1, k + 1):
        for j in a:
            if i - j >= 0:
                dp[i] |= not dp[i - j]
    print("First" if dp[k] else "Second")


if __name__ == '__main__':
    p_k()

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
dp = [0]*(K+1)
for i in range(1, K+1):
    flag = 0
    for ai in a:
        if i-ai<0:
            break
        if dp[i-ai] == 0:
            flag = 1
    dp[i] = flag
if dp[-1] == 1:
    print('First')
else:
    print('Second')

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))

dp=[False]*(k+1+max(a))

for i in range(1+k):
  if not dp[i]:
    for x in a:
      dp[i+x]=True

print(("Second","First")[dp[k]])