File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed
Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` cpp
2+
3+ #include < iostream>
4+ #include < vector>
5+ using namespace std ;
6+
7+ int main ()
8+ {
9+ cin.tie(0)->sync_with_stdio(0);
10+
11+ int N, M;
12+ cin >> N;
13+ vector<int> A(N);
14+ for (int &i : A) cin >> i;
15+ cin >> M;
16+ vector<int> B(M);
17+ for (int &i : B) cin >> i;
18+
19+ vector<int> R;
20+ int idxA = 0, idxB = 0;
21+ while (idxA < N && idxB < M) {
22+ bool suc = 0;
23+ for (int x = 100; x >= 1; x--) {
24+ int res = 0;
25+ int new_idxA = idxA, new_idxB = idxB;
26+ for (int i = idxA; i < N; i++) if (A[i] == x) { res++; new_idxA = i + 1; break; }
27+ for (int i = idxB; i < M; i++) if (B[i] == x) { res++; new_idxB = i + 1; break; }
28+ if (res == 2) {
29+ idxA = new_idxA, idxB = new_idxB;
30+ R.push_back(x);
31+ suc = 1;
32+ break;
33+ }
34+ }
35+ if (!suc) break;
36+ }
37+ cout << R.size() << '\n';
38+ for (int i : R) cout << i << ' ';
39+
40+ }
41+
42+ ```
You can’t perform that action at this time.
0 commit comments