Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <vector>
- #include <cmath>
- #include <string>
- #include <algorithm>
- #include <string>
- #include <string.h>
- #define F first
- #define S second
- using namespace std;
- vector <int> a, b;
- int main()
- {
- ios_base::sync_with_stdio(0);
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- int n;
- cin >> n;
- a.resize(n);
- for (int i = 0; i < n; i++)
- cin >> a[i];
- sort(a.begin(), a.end());
- reverse(a.begin(), a.end());
- int m;
- cin >> m;
- b.resize(m);
- for (int i = 0; i < m; i++)
- cin >> b[i];
- sort(b.begin(), b.end());
- reverse(b.begin(), b.end());
- int ans = 0;
- for (int i = 0; i < m; i++)
- if (a[i] > b[i])
- {
- ans += b[i];
- a.push_back(a[i] - b[i]);
- }
- else
- ans += a[i];
- cout << ans << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement