Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- ifstream fin("bac.txt");
- #define NMAX (int)1e6 + 3
- int n, m, arr1[NMAX], arr2[NMAX];
- int ans[NMAX * 2] = {-1}, top;
- void readArr(int len, int arr[]) {
- for (int i = 1; i <= len; i++) {
- fin >> arr[i];
- }
- }
- int getMini(int a, int b) {
- return a > b ? b : a;
- }
- void addRest(int it, int len, int arr[]) {
- while (it <= len) {
- if (ans[top] % 2 != arr[it] % 2) {
- ans[++top] = arr[it];
- }
- it++;
- }
- }
- void intercl() {
- int it1 = 1, it2 = 1;
- while (it1 <= m && it2 <= n) {
- int mini = getMini(arr1[it1], arr2[it2]);
- if (ans[top] == -1 || (ans[top] % 2 != mini % 2)) {
- ans[++top] = mini;
- }
- if (arr1[it1] == mini && arr2[it2] == mini) {
- it1++, it2++;
- } else if (arr2[it2] != mini && arr1[it1] == mini) {
- it1++;
- } else {
- it2++;
- }
- }
- addRest(it1, m, arr1);
- addRest(it2, n, arr2);
- }
- void write() {
- for (int i = 1; i <= top; i++) {
- cout << ans[i] << ' ';
- }
- }
- int main() {
- fin >> m >> n;
- readArr(m, arr1);
- readArr(n, arr2);
- intercl();
- write();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement