Skip to content

Commit 467e43a

Browse files
committed
K
1 parent 71ffde9 commit 467e43a

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

Stones.java

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import java.util.*;
2+
import java.io.*;
3+
4+
public class Stones {
5+
6+
public static void main(String[] args) throws IOException {
7+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
String[] s = br.readLine().split(" ");
9+
int n = Integer.parseInt(s[0]);
10+
int k = Integer.parseInt(s[1]);
11+
s = br.readLine().split(" ");
12+
int[] arr = new int[n];
13+
14+
for (int i = 0; i < n; i++)
15+
arr[i] = Integer.parseInt(s[i]);
16+
17+
Arrays.sort(arr);
18+
19+
boolean[] dp = new boolean[k + 1];
20+
21+
for (int i = 1; i <= k; i++) {
22+
for (int j = 0; j < n && arr[j] <= i; j++) {
23+
if (!dp[i - arr[j]]) {
24+
dp[i] = true;
25+
break;
26+
}
27+
}
28+
}
29+
if (dp[k])
30+
System.out.println("First");
31+
else
32+
System.out.println("Second");
33+
}
34+
35+
}

0 commit comments

Comments
 (0)