Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define endl '\n'
- int main()
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int m, n;
- cin >> m >> n;
- vector<pair<int, char> > xiy;
- for(int i = 0; i < m - 1; ++i)
- {
- int a;
- cin >> a;
- xiy.emplace_back(a, 'x');
- }
- for(int i = 0; i < n - 1; ++i)
- {
- int a;
- cin >> a;
- xiy.emplace_back(a, 'y');
- }
- sort(xiy.begin(), xiy.end());
- int ile_x = 1, ile_y = 1, answ = 0;
- for(int i = xiy.size() - 1; i >= 0; --i)
- {
- if (xiy[i].second == 'x')
- {
- answ += ile_y * xiy[i].first;
- ++ile_x;
- }
- else
- {
- answ += ile_x * xiy[i].first;
- ++ile_y;
- }
- }
- cout << answ;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement