Advertisement
Augenbrauen

czekolada.

Dec 30th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.                      
  3. using namespace std;
  4. #define endl '\n'
  5.    
  6. int main()
  7. {
  8.     ios_base::sync_with_stdio(0);
  9.     cin.tie(0);
  10.  
  11.     int m, n;
  12.     cin >> m >> n;
  13.     vector<pair<int, char> > xiy;
  14.     for(int i = 0; i < m - 1; ++i)
  15.     {
  16.         int a;
  17.         cin >> a;
  18.         xiy.emplace_back(a, 'x');
  19.     }
  20.     for(int i = 0; i < n - 1; ++i)
  21.     {
  22.         int a;
  23.         cin >> a;
  24.         xiy.emplace_back(a, 'y');
  25.     }
  26.     sort(xiy.begin(), xiy.end());
  27.     int ile_x = 1, ile_y = 1, answ = 0;
  28.     for(int i = xiy.size() - 1; i >= 0; --i)
  29.     {
  30.         if (xiy[i].second == 'x')
  31.         {
  32.             answ += ile_y * xiy[i].first;
  33.             ++ile_x;
  34.         }
  35.         else
  36.         {
  37.             answ += ile_x * xiy[i].first;
  38.             ++ile_y;
  39.         }      
  40.     }
  41.     cout << answ;
  42.  
  43.  
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement