Advertisement
double_trouble

3

Nov 8th, 2014
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <cmath>
  5. #include <string>
  6. #include <algorithm>
  7. #include <string>
  8. #include <string.h>
  9.  
  10. #define F first
  11. #define S second
  12.  
  13.  
  14.  
  15. using namespace std;
  16.  
  17. vector <int> a, b;
  18.  
  19. int main()
  20. {
  21.     ios_base::sync_with_stdio(0);
  22.     freopen("input.txt", "r", stdin);
  23.     freopen("output.txt", "w", stdout);
  24.     int n;
  25.     cin >> n;
  26.     a.resize(n);
  27.     for (int i = 0; i < n; i++)
  28.         cin >> a[i];
  29.     sort(a.begin(), a.end());
  30.     reverse(a.begin(), a.end());
  31.     int m;
  32.     cin >> m;
  33.     b.resize(m);
  34.     for (int i = 0; i < m; i++)
  35.         cin >> b[i];
  36.     sort(b.begin(), b.end());
  37.     reverse(b.begin(), b.end());
  38.     int ans = 0;
  39.     for (int i = 0; i < m; i++)
  40.         if (a[i] > b[i])
  41.         {
  42.             ans += b[i];
  43.             a.push_back(a[i] - b[i]);
  44.         }
  45.         else
  46.             ans += a[i];
  47.     cout << ans << endl;
  48.     return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement