Advertisement
AdelKhalilov

Untitled

Jan 23rd, 2017
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.99 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.Locale;
  3. import java.util.StringTokenizer;
  4.  
  5.  
  6. public class D {
  7. String filename = "addition";//filename here, System.in/out if no file
  8.  
  9. FastScanner in;
  10. PrintWriter out;
  11.  
  12.  
  13. void solve() {
  14. //your code here
  15. int n = in.nextInt();
  16. int k = in.nextInt();
  17. int[] res = new int[k];
  18. for (int i = 0; i < k; i++) {
  19. res[i] = in.nextInt();
  20. }
  21. int a = n;
  22. int b = n;
  23. int x = k;
  24. int i = 0;
  25. int z = -1;
  26. int ans = -1;
  27. boolean fl = true;
  28. boolean f = true;
  29. while (x > 0) {
  30. if (x < a && fl == true) {
  31. z = i;
  32. fl = false;
  33. }
  34. if (x < b && fl == true) {
  35. z = i;
  36. fl = false;
  37. }
  38. if (fl == false && f == true) {
  39. ans = i;
  40. f = false;
  41. }
  42.  
  43. if ((a == 1 || b == 1) && f == true) {
  44. ans = i;
  45. f = false;
  46. }
  47. if (res[i] == 1) {
  48. a--;
  49. } else {
  50. b--;
  51. }
  52. x--;
  53. i++;
  54. }
  55. boolean last_game = true;
  56. if (fl == true) {
  57. last_game = false;
  58. }
  59. if (z == -1) {
  60. z = k;
  61. }
  62. if (ans == -1) {
  63. ans = k;
  64. }
  65. out.println(z);
  66. for (int j = 0; j < ans; j++) {
  67. out.print(0 + " ");
  68. }
  69. for (int j = 0; j < k - ans; j++) {
  70. if (j != k - ans - 1) {
  71.  
  72. out.print(1 + " ");
  73. } else {
  74. if (last_game == false) {
  75. out.print(0 + " ");
  76. } else {
  77. out.print(1 + " ");
  78. }
  79. }
  80. }
  81. }
  82.  
  83. void run() throws IOException {
  84. InputStream input = System.in;
  85. OutputStream output = System.out;
  86. /* try {
  87. File f = new File(filename + ".in");
  88. if (f.exists() && f.canRead()) {
  89. input = new FileInputStream(f);
  90. output = new FileOutputStream(filename + ".out");
  91. }
  92. } catch (IOException e) {
  93. }*/
  94. in = new FastScanner(input);
  95. out = new PrintWriter(new BufferedOutputStream(output));
  96. solve();
  97. in.close();
  98. out.close();
  99. }
  100.  
  101. public static void main(String[] args) throws IOException {
  102. Locale.setDefault(Locale.US);
  103. new D().run();
  104. }
  105.  
  106. class FastScanner implements Closeable {
  107. private BufferedReader br;
  108. private StringTokenizer tokenizer;
  109.  
  110. public FastScanner(InputStream stream) throws FileNotFoundException {
  111. br = new BufferedReader(new InputStreamReader(stream));
  112. }
  113.  
  114. public String next() {
  115. while (tokenizer == null || !tokenizer.hasMoreTokens()) {
  116. try {
  117. tokenizer = new StringTokenizer(br.readLine());
  118. } catch (IOException e) {
  119. throw new RuntimeException(e);
  120. }
  121. }
  122. return tokenizer.nextToken();
  123. }
  124.  
  125. public String nextLine() {
  126. if (tokenizer == null || !tokenizer.hasMoreTokens()) {
  127. try {
  128. return br.readLine();
  129. } catch (IOException e) {
  130. throw new RuntimeException(e);
  131. }
  132. }
  133. return tokenizer.nextToken("\n");
  134. }
  135.  
  136. public int nextInt() {
  137. return Integer.parseInt(next());
  138. }
  139.  
  140. public long nextLong() {
  141. return Long.parseLong(next());
  142. }
  143.  
  144. public double nextDouble() {
  145. return Double.parseDouble(next());
  146. }
  147.  
  148. @Override
  149. public void close() throws IOException {
  150. br.close();
  151. }
  152. }
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement