Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.Locale;
- import java.util.StringTokenizer;
- public class D {
- String filename = "addition";//filename here, System.in/out if no file
- FastScanner in;
- PrintWriter out;
- void solve() {
- //your code here
- int n = in.nextInt();
- int k = in.nextInt();
- int[] res = new int[k];
- for (int i = 0; i < k; i++) {
- res[i] = in.nextInt();
- }
- int a = n;
- int b = n;
- int x = k;
- int i = 0;
- int z = -1;
- int ans = -1;
- boolean fl = true;
- boolean f = true;
- while (x > 0) {
- if (x < a && fl == true) {
- z = i;
- fl = false;
- }
- if (x < b && fl == true) {
- z = i;
- fl = false;
- }
- if (fl == false && f == true) {
- ans = i;
- f = false;
- }
- if ((a == 1 || b == 1) && f == true) {
- ans = i;
- f = false;
- }
- if (res[i] == 1) {
- a--;
- } else {
- b--;
- }
- x--;
- i++;
- }
- boolean last_game = true;
- if (fl == true) {
- last_game = false;
- }
- if (z == -1) {
- z = k;
- }
- if (ans == -1) {
- ans = k;
- }
- out.println(z);
- for (int j = 0; j < ans; j++) {
- out.print(0 + " ");
- }
- for (int j = 0; j < k - ans; j++) {
- if (j != k - ans - 1) {
- out.print(1 + " ");
- } else {
- if (last_game == false) {
- out.print(0 + " ");
- } else {
- out.print(1 + " ");
- }
- }
- }
- }
- void run() throws IOException {
- InputStream input = System.in;
- OutputStream output = System.out;
- /* try {
- File f = new File(filename + ".in");
- if (f.exists() && f.canRead()) {
- input = new FileInputStream(f);
- output = new FileOutputStream(filename + ".out");
- }
- } catch (IOException e) {
- }*/
- in = new FastScanner(input);
- out = new PrintWriter(new BufferedOutputStream(output));
- solve();
- in.close();
- out.close();
- }
- public static void main(String[] args) throws IOException {
- Locale.setDefault(Locale.US);
- new D().run();
- }
- class FastScanner implements Closeable {
- private BufferedReader br;
- private StringTokenizer tokenizer;
- public FastScanner(InputStream stream) throws FileNotFoundException {
- br = new BufferedReader(new InputStreamReader(stream));
- }
- public String next() {
- while (tokenizer == null || !tokenizer.hasMoreTokens()) {
- try {
- tokenizer = new StringTokenizer(br.readLine());
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
- return tokenizer.nextToken();
- }
- public String nextLine() {
- if (tokenizer == null || !tokenizer.hasMoreTokens()) {
- try {
- return br.readLine();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
- return tokenizer.nextToken("\n");
- }
- public int nextInt() {
- return Integer.parseInt(next());
- }
- public long nextLong() {
- return Long.parseLong(next());
- }
- public double nextDouble() {
- return Double.parseDouble(next());
- }
- @Override
- public void close() throws IOException {
- br.close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement