about summary refs log tree commit diff
path: root/others/easy20160714/22.c
blob: d38c0f5c9bad4496e4262ba2fd90446a0be80d3c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>

int main()
{
	FILE *fi = fopen("INP.TXT", "r"), *fo = fopen("OUT.TXT", "w");
	int n, m, i, j = 0, *a, b;

	fscanf(fi, "%d %d", &n, &m);
	a = malloc(n * sizeof(int));

	for (i = 0; i < n; i++)
		fscanf(fi, "%d", a + i);

	for (i = 0; i < m; i++) {
		fscanf(fi, "%d", &b);
		while (a[j] < b && j < n)
			fprintf(fo, "%d ", a[j++]);
		fprintf(fo, "%d ", b);
	}

	while (j < n)
		fprintf(fo, "%d ", a[j++]);

	fputc(10, fo);
	fcloseall();

	return 0;
}