def solve():
n, m = map(int, input().split())
b = list(map(int, input().split()))
g = list(map(int, input().split()))
if max(b) > min(g):
print(-1)
return
if max(b) == min(g):
ans = sum(b) * m - max(b) * m + sum(g)
print(ans)
return
max_val = 0
second_max = 0
for i in b:
if i > max_val:
second_max = max_val
max_val = i
elif i > second_max:
second_max = i
ans = sum(b) * m - (max_val * (m - 1)) - second_max + sum(g)
print(ans)
solve()
#include <bits/stdc++.h>
#define io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define ll long long
using namespace std;
typedef pair<int, int> pii;
const ll MOD = 1e9L + 7;
const int INF = 1e9+5;
const int N = 1e5+10;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
char dir[] = {'U', 'L', 'D', 'R'};
template <typename T> void min_self(T &a, T b) { a = min(a, b); }
template <typename T> void max_self(T &a, T b) { a = max(a, b); }
bool cmp(pii &a, pii &b) {
return a.S < b.S;
}
int main() {
io;
int n, m;
cin >> n >> m;
ll bsum = 0, gsum = 0;
ll bmx = 0, gmn = LLONG_MAX, scd_bmx = 0;
// Read and calculate the maximum and second maximum values for the first set
for (int i = 0; i < n; i++) {
ll d;
cin >> d;
if (d > bmx) {
scd_bmx = bmx;
bmx = d;
} else if (d > scd_bmx) {
scd_bmx = d;
}
bsum += d;
}
// Read and calculate the minimum value for the second set
for (int j = 0; j < m; j++) {
ll d;
cin >> d;
min_self(gmn, d);
gsum += d;
}
ll cur = 0;
if (bmx > gmn) {
// If the maximum value in the first set is greater than the minimum in the second set, it's impossible.
puts("-1");
return 0;
}
if (bmx == gmn) {
// If the maximum value in the first set equals the minimum in the second set,
// calculate the result as described in the code.
cur += m * bsum;
cur += gsum;
cur -= bmx * m;
cout << cur << "\n";
} else {
// If the maximum value in the first set is less than the minimum in the second set,
// calculate the result as described in the code.
cur += m * bsum;
cur += gsum;
cur -= (m - 1) * bmx + scd_bmx;
cout << cur << "\n";
}
return 0;
}
1660B - Vlad and Candies | 1472C - Long Jumps |
1293D - Aroma's Search | 918A - Eleven |
1237A - Balanced Rating Changes | 1616A - Integer Diversity |
1627B - Not Sitting | 1663C - Pōja Verdon |
1497A - Meximization | 1633B - Minority |
688B - Lovely Palindromes | 66B - Petya and Countryside |
1557B - Moamen and k-subarrays | 540A - Combination Lock |
1553C - Penalty | 1474E - What Is It |
1335B - Construct the String | 1004B - Sonya and Exhibition |
1397A - Juggling Letters | 985C - Liebig's Barrels |
115A - Party | 746B - Decoding |
1424G - Years | 1663A - Who Tested |
1073B - Vasya and Books | 195B - After Training |
455A - Boredom | 1099A - Snowball |
1651D - Nearest Excluded Points | 599A - Patrick and Shopping |