Language: C++

#include <iostream>
#include <set>
#include <algorithm>
 
using namespace std;

int main() {
   #define int long long;
    int W, H;
    cin >> W >> H;
    set<pair<int, bool>> S;
    for (int i = 0; i < W; i++) {
        int k;
        cin >> k;
        S.insert(make_pair(k, true));
    }
    for (int i = 0; i < H; i++) {
        int k;
        cin >> k;
        S.insert(make_pair(k, false));
    }
   
    long long res = 0;
    W++; H++;
    while (!S.empty()) {
        auto it = S.begin();
        if (it->second) {
            res += max(H, 0) * it->first;
            W--;
        } else {
            res += max(W, 0) * it->first;
            H--;
        }
        S.erase(S.begin());
    }
    cout << res << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:8:21: error: declaration does not declare anything [-fpermissive]
    8 |    #define int long long;
      |                     ^~~~
a.cc:9:5: note: in expansion of macro 'int'
    9 |     int W, H;
      |     ^~~
a.cc:9:9: error: 'W' was not declared in this scope
    9 |     int W, H;
      |         ^
a.cc:9:12: error: 'H' was not declared in this scope
    9 |     int W, H;
      |            ^
a.cc:8:21: error: wrong number of template arguments (1, should be 2)
    8 |    #define int long long;
      |                     ^~~~
a.cc:11:14: note: in expansion of macro 'int'
   11 |     set<pair<int, bool>> S;
      |              ^~~
In file included from /usr/include/c++/14/string:48,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_iterator.h:3013:12: note: provided for 'template<class _T1, class _T2> struct std::pair'
 3013 |     struct pair;
      |            ^~~~
a.cc:11:9: error: template argument 1 is invalid
   11 |     set<pair<int, bool>> S;
      |         ^
a.cc:11:9: error: template argument 2 is invalid
a.cc:11:9: error: template argument 3 is invalid
a.cc:11:17: error: expected primary-expression before ',' token
   11 |     set<pair<int, bool>> S;
      |                 ^
a.cc:11:19: error: expected primary-expression before 'bool'
   11 |     set<pair<int, bool>> S;
      |                   ^~~~
a.cc:8:21: error: declaration does not declare anything [-fpermissive]
    8 |    #define int long long;
      |                     ^~~~
a.cc:12:10: note: in expansion of macro 'int'
   12 |     for (int i = 0; i < W; i++) {
      |          ^~~
a.cc:12:14: error: 'i' was not declared in this scope
   12 |     for (int i = 0; i < W; i++) {
      |              ^
a.cc:12:26: error: expected ')' before ';' token
   12 |     for (int i = 0; i < W; i++) {
      |         ~                ^
      |                          )
a.cc:12:28: error: 'i' was not declared in this scope
   12 |     for (int i = 0; i < W; i++) {
      |                            ^
a.cc:8:21: error: declaration does not declare anything [-fpermissive]
    8 |    #define int long long;
      |                     ^~~~
a.cc:17:10: note: in expansion of macro 'int'
   17 |     for (int i = 0; i < H; i++) {
      |          ^~~
a.cc:17:26: error: expected ')' before ';' token
   17 |     for (int i = 0; i < H; i++) {
      |         ~                ^
      |                          )
a.cc:25:13: error: 'S' was not declared in this scope
   25 |     while (!S.empty()) {
      |             ^