Created
October 26, 2017 14:15
-
-
Save chermehdi/a2e6ad35f2adaaa292ccdf12de50f90a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.util.*; | |
import java.util.stream.Collectors; | |
public class Bachet { | |
public static void main(String args[]) throws Exception { | |
BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); | |
PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); | |
String line; | |
while ((line = in.readLine()) != null) { | |
List<Integer> ints = Arrays.stream(line.split(" ")).map(Integer::parseInt).collect(Collectors.toList()); | |
int n = ints.get(0); | |
int m = ints.get(1); | |
int[] arr = new int[m]; | |
int pt = 0; | |
boolean[] f = new boolean[1000005]; | |
for (int i = 2; i < ints.size(); i++) { | |
arr[pt++] = ints.get(i); | |
} | |
for (int i = 1; i <= n; i++) { | |
for (int j = 0; j < m; j++) { | |
if (i >= arr[j] && !f[i - arr[j]]) { | |
f[i] = true; | |
break; | |
} | |
} | |
} | |
out.println(f[n] ? "Stan wins" : "Ollie wins"); | |
} | |
out.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment