CF457B.Distributed Join

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Piegirl was asked to implement two table join operation for distributed database system, minimizing the network traffic.

Suppose she wants to join two tables, A and B. Each of them has certain number of rows which are distributed on different number of partitions. Table A is distributed on the first cluster consisting of m partitions. Partition with index i has a__i rows from A. Similarly, second cluster containing table B has n partitions, i-th one having b__i rows from B.

In one network operation she can copy one row from any partition to any other partition. At the end, for each row from A and each row from B there should be a partition that has both rows. Determine the minimal number of network operations to achieve this.

Piegirl 被要求为分布式数据库系统实现两张表的连接(join)操作,并使网络通信量最小化。

假设她需要连接两张表 AA 和 BB。每张表的若干行被分别分布于不同数量的分区中。表 AA 分布在由 mm 个分区组成的第一个集群中;索引为 ii 的分区包含 aia_i 行来自 AA 的数据。类似地,包含表 BB 的第二个集群有 nn 个分区,其中第 ii 个分区包含 bib_i 行来自 BB 的数据。

每次网络操作可将任意一个分区中的一行数据复制到任意其他分区。最终,对 AA 中的每一行和 BB 中的每一行,都必须存在某个分区,该分区同时包含这两行。求达成此目标所需的最少网络操作次数。

输入格式

First line contains two integer numbers, m and n (1 ≤ m, n ≤ 105). Second line contains description of the first cluster with m space separated integers, a__i (1 ≤ a__i ≤ 109). Similarly, third line describes second cluster with n space separated integers, b__i (1 ≤ b__i ≤ 109).

第一行包含两个整数 mm 和 nn(1 ≤ m, n ≤ 1051 \le m, n \le 10^5)。
第二行包含第一个簇的描述,即 mm 个用空格分隔的整数 aia_i(1 ≤ ai ≤ 1091 \le a_i \le 10^9)。
类似地,第三行用 nn 个用空格分隔的整数 bib_i(1 ≤ bi ≤ 1091 \le b_i \le 10^9)描述第二个簇。

输出格式

Print one integer — minimal number of copy operations.

输出一个整数——最小的复制操作次数。

输入输出样例

  • 输入#1

    2 2
    2 6
    3 100

    输出#1

    11
  • 输入#2

    2 3
    10 10
    1 1 1

    输出#2

    6

说明/提示

In the first example it makes sense to move all the rows to the second partition of the second cluster which is achieved in 2 + 6 + 3 = 11 operations

In the second example Piegirl can copy each row from B to the both partitions of the first cluster which needs 2·3 = 6 copy operations.

在第一个例子中,将所有行移动到第二个簇的第二分区是合理的,这需要 2 + 6 + 3 = 112 + 6 + 3 = 11 次操作。

在第二个例子中,Piegirl 可以将 B 中的每一行都复制到第一个簇的两个分区中,这需要 2⋅3 = 62·3 = 6 次复制操作。

输入解题思路,AI测评打分。不知道怎么写?

首页