比赛 2025.12.6 评测结果 WWWWWWMWWW
题目名称 巧克力 最终得分 0
用户昵称 LikableP 运行时间 0.173 s
代码语言 C++ 内存使用 1.66 MiB
提交时间 2025-12-06 12:01:49
显示代码纯文本
#include <cstdio>
#include <cctype>

template <typename T> T read() {
  T res = 0, f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) res = (res << 3) + (res << 1) + (ch ^ 48);
  return res * f;
}

void write(__int128 x, char ed = '\n') {
  if (x < 0) x = -x, putchar('-');
  static int sta[64], top = 0;
  do {
    sta[++top] = x % 10;
    x /= 10;
  } while (x);
  while (top) {
    putchar(sta[top--] ^ 48);
  }
  putchar(ed);
}

template <typename T> void write(T x, char ed = '\n') {
  write((__int128)x, ed);
}

#include <algorithm>
typedef long long ll;

const int MAXN = 1e4 + 10;

enum Way {
  Verticle,
  Horizontal
};

struct Cost {
  Way way;
  ll cost;
} a[MAXN];

int n, m;

int main() {
  #ifdef LOCAL
    freopen("!input.in", "r", stdin);
    freopen("!output.out", "w", stdout);
  #else
    freopen("chocolate.in", "r", stdin);
    freopen("chocolate.out", "w", stdout);
  #endif
  n = read<int>(), m = read<int>();
  for (int i = 1; i <= n - 1; ++i) {
    a[i].way = Verticle;
    a[i].cost = read<ll>();
  }
  for (int i = n; i <= n + m - 2; ++i) {
    a[i].way = Horizontal;
    a[i].cost = read<ll>();
  }

  std::sort(a + 1, a + n + m - 2 + 1, [](Cost x, Cost y) {
    return x.cost > y.cost;
  });

  ll ans = 0, horizontalmul = 1, verticlemul = 1;
  for (int i = 1; i <= n; ++i) {
    if (a[i].way == Verticle) {
      ans += a[i].cost * verticlemul;
      fprintf(stderr, "ans += %lld * %lld\n", a[i].cost * verticlemul);
      horizontalmul++;
    } else {
      ans += a[i].cost * horizontalmul;
      fprintf(stderr, "ans += %lld * %lld\n", a[i].cost * horizontalmul);
      verticlemul++;
    }
  }

  write(ans);
  return 0;
}