Advertisement
AdelKhalilov

Untitled

Jan 23rd, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.66 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 && fl == false) {
  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. if (z == -1) {
  56. z = k;
  57. }
  58. if (ans == -1){
  59. ans = k;
  60. }
  61. out.println(z);
  62. for (int j = 0; j < ans; j++) {
  63. out.print(0 + " ");
  64. }
  65. for (int j = 0; j < k - ans; j++) {
  66. out.print(1 + " ");
  67. }
  68. }
  69.  
  70. void run() throws IOException {
  71. InputStream input = System.in;
  72. OutputStream output = System.out;
  73. /* try {
  74. File f = new File(filename + ".in");
  75. if (f.exists() && f.canRead()) {
  76. input = new FileInputStream(f);
  77. output = new FileOutputStream(filename + ".out");
  78. }
  79. } catch (IOException e) {
  80. }*/
  81. in = new FastScanner(input);
  82. out = new PrintWriter(new BufferedOutputStream(output));
  83. solve();
  84. in.close();
  85. out.close();
  86. }
  87.  
  88. public static void main(String[] args) throws IOException {
  89. Locale.setDefault(Locale.US);
  90. new D().run();
  91. }
  92.  
  93. class FastScanner implements Closeable {
  94. private BufferedReader br;
  95. private StringTokenizer tokenizer;
  96.  
  97. public FastScanner(InputStream stream) throws FileNotFoundException {
  98. br = new BufferedReader(new InputStreamReader(stream));
  99. }
  100.  
  101. public String next() {
  102. while (tokenizer == null || !tokenizer.hasMoreTokens()) {
  103. try {
  104. tokenizer = new StringTokenizer(br.readLine());
  105. } catch (IOException e) {
  106. throw new RuntimeException(e);
  107. }
  108. }
  109. return tokenizer.nextToken();
  110. }
  111.  
  112. public String nextLine() {
  113. if (tokenizer == null || !tokenizer.hasMoreTokens()) {
  114. try {
  115. return br.readLine();
  116. } catch (IOException e) {
  117. throw new RuntimeException(e);
  118. }
  119. }
  120. return tokenizer.nextToken("\n");
  121. }
  122.  
  123. public int nextInt() {
  124. return Integer.parseInt(next());
  125. }
  126.  
  127. public long nextLong() {
  128. return Long.parseLong(next());
  129. }
  130.  
  131. public double nextDouble() {
  132. return Double.parseDouble(next());
  133. }
  134.  
  135. @Override
  136. public void close() throws IOException {
  137. br.close();
  138. }
  139. }
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement