```cpp int p, q; const int N = 5005; int a[N], b[N]; void sol() { cin >> p >> q; for (int i = 0; i < p; i++) cin >> a[i]; for (int i = 0; i < q; i++) cin >> b[i]; map<int, int> mp; for (int i = 0; i < p; i++) mp[a[i]]++; vector<int> ans; for (int i = 0; i < q; i++) { if (mp.count(b[i])) { int k = mp[b[i]]; while (k--) { ans.push_back(b[i]); } mp.erase(b[i]); } } for (auto it : mp) { int k = it.second; while (k--) ans.push_back(it.first); } for (int n : ans) cout << n << ' ' << endl; } ```

相关推荐

牛客771574427号:恭喜你,华杰
点赞 评论 收藏
分享
牛客网
牛客企业服务