Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- int n = in.nextInt();
- int m = in.nextInt();
- int[] a = new int[n];
- int[] b = new int[m];
- for (int i = 0; i < n; i++) {
- a[i] = in.nextInt();
- }
- for (int i = 0; i < m; i++) {
- b[i] = in.nextInt();
- }
- int[] c = new int[n+m];
- int i = 0;
- int j = 0;
- int k = 0;
- while (i < n && j < m){
- if (a[i] < b[j]){
- c[k++] = a[i++];
- } else {
- c[k++] = b[j++];
- }
- }
- while (i < n ){
- c[k++] = a[i++];
- }
- while (j < m){
- c[k++] = b[j++];
- }
- for (int t = 0; t < n + m; t++) {
- System.out.print(c[t] + " ");
- }
- in.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement