-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStones.java
More file actions
35 lines (28 loc) · 741 Bytes
/
Stones.java
File metadata and controls
35 lines (28 loc) · 741 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.util.*;
import java.io.*;
public class Stones {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] s = br.readLine().split(" ");
int n = Integer.parseInt(s[0]);
int k = Integer.parseInt(s[1]);
s = br.readLine().split(" ");
int[] arr = new int[n];
for (int i = 0; i < n; i++)
arr[i] = Integer.parseInt(s[i]);
Arrays.sort(arr);
boolean[] dp = new boolean[k + 1];
for (int i = 1; i <= k; i++) {
for (int j = 0; j < n && arr[j] <= i; j++) {
if (!dp[i - arr[j]]) {
dp[i] = true;
break;
}
}
}
if (dp[k])
System.out.println("First");
else
System.out.println("Second");
}
}