func_code_string: #include <bits/stdc++.h>   using namespace std;   bool check(vector<long long> a, long long m, long long n) {     vector<long long> v(n + 1, 0);     for (long long i = 0; i < n; i++) {       v[a[i]] += 1;     }     set<pair<long long, long long>, greater<pair<long long, long long>>> s;     for (long long i = 1; i < n + 1; i++) {       if (v[i]) {         s.insert({v[i], i});       }     }     vector<long long> b;     for (long long i = 0; i < n; i++) {       if (i >= m and v[b[i - m]]) {         s.insert({v[b[i - m]], b[i - m]});       }       if (s.empty()) return false;       pair<long long, long long> p = *(s.begin());       b.push_back(p.second);       s.erase(p);       v[p.second] -= 1;     }     return true;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long n, m;     cin >> n >> m;     vector<long long> a(n), b(m);     for (long long i = 0; i < n; i++) cin >> a[i];     for (long long i = 0; i < m; i++) cin >> b[i];     sort(a.begin(), a.end());     sort(b.begin(), b.end());     if (a[n - 1] > b[0]) {       cout <<  -1 n ;       return 0;     }     long long ans = 0;     for (long long i = 0; i < n; i++) ans += a[i] * m;     long long g = n - 1, h = m - 1;     bool is = false;     for (long long i = m - 1; i >= 0; i--) {       while (g >= 0 && h == 0) {         g--;         h = m - 1;       }       if (b[i] == a[n - 1]) {         break;       }       if (g < 0) {         cout <<  -1 n ;         return 0;       }       ans += b[i] - a[g];       h--;     }     cout << ans << endl;     return 0;   }   