-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathC - Pair Programming.cpp
92 lines (85 loc) · 2.67 KB
/
C - Pair Programming.cpp
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Problem Link : https://codeforces.com/contest/1547/problem/C
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t;
for (int z = 1; z <= t; z++)
{
int k,n,m;
cin >> k >> n >> m;
int arr1[n];
int arr2[m];
for(int i = 0; i < n; i++){
cin >> arr1[i];
}
for(int i = 0; i < m; i++){
cin >> arr2[i];
}
vector<int> ans;
bool check = true;
int i = 0;
int j = 0;
while(i < n && j < m){
// if both are tring to edit link which is not present then we will mark check as false and break the loop
if(arr1[i] > k && arr2[j] > k){
check = false;
break;
}
// if Monocarp wants to add line or edit the line which is present then we will allow him
if(arr1[i] <= k){
if(arr1[i] == 0) // if he is adding a line then we will increment number of line too
k++;
ans.push_back(arr1[i]);
i++;
}
// if Polycarp is wants to add line or edit the line which is present then we will allow him
if(arr2[j] <= k){
if(arr2[j] == 0) // if he is addint a line then we will increment number of line too
k++;
ans.push_back(arr2[j]);
j++;
}
}
// if some where both are tring to edit line which is not present then we will print -1 and continue to next test case
if(check == false){
cout << -1 << endl;
continue;
}
// if now some changes by Monocarp are remaining then we will do that ans check for same
while(i < n){
if(arr1[i] <= k){
if(arr1[i] == 0)
k++;
ans.push_back(arr1[i]);
i++;
}else{
check = false;
break;
}
}
// if now some changes by Polycarp are remaining then we will do that ans check for same
while(j < m){
if(arr2[j] <= k){
if(arr2[j] == 0)
k++;
ans.push_back(arr2[j]);
j++;
}else{
check = false;
break;
}
}
// at last if check is false then we will print -1 else we will print our ans
if(check){
for(int i = 0; i < ans.size(); i++){
cout << ans[i] << " ";
}
cout << endl;
}else{
cout << -1 << endl;
}
}
return 0;
}