3737 - Charlie and the ACF

Created by José Ignacio Cruz Moreira
Added by ymondelo20 (2016-09-10)
Limits
Total Time: 7000 MS | Test Time: 1000 MS |Memory: 256 MB | Output: 64 MB | Size: 16 KB
Enabled languages
Available in

Description

Charlie works at the Association of Chocolate Making (ACM) as a manager of one of its factories. Recently, a strange phenomenon is affecting the quality of the chocolates produced by the factory. Oddly, the phenomenon increases the quality of all the chocolates produced in exactly two production lines: A and B. Charlie, as the good manager he is, wants to take advantage of this phenomenon to improve the quality of the chocolates as much as possible. The scientists of ACM have discovered the function that rules the phenomenon: The Absolute Chocolate Function (abbreviated as ACF). This function equals the sum of the absolute differences between each individual chocolate quality Ai from production line A paired with each individual chocolate quality Bj from production line B. Mathematically, the Absolute Chocolate Function can be expressed (using 1-based indexing) as follows:



Now, the scientists need to evaluate the function for the two impacted production lines. As the number of chocolates on both productions lines can be very big, they ask you as a programmer of ACM to calculate the Absolute Chocolate Function for these two production lines.
Charlie trabaja en la Asociación de Fábricas de Chocolate (ACM) como administrador de una de sus fábricas. Recientemente un extraño fenómeno está afectando la calidad de los chocolates producidos por la fábrica. Extrañamente el fenómeno incrementa la calidad de todos los chocolates producidos en exactamente dos líneas de producción: A y B. Charlie, como buen administrador que es quiere tomar ventaja de este fenómeno para mejorar la calidad de los chocolates tanto como sea posible. Los científicos de la ACM han descubierto la función que regula este fenómeno: La Función Absoluta del Chocolate (abreviada como ACF). Esta función es igual a la suma de la diferencia absoluta entre la calidad individual de cada chocolate Ai para la línea de producción A emparejado con la calidad individual de cada chocolate Bj para línea de producción B. Matemáticamente, la ACF puede ser expresada (usando indexación de base 1) como sigue:


Ahora, los científicos necesitan evaluar la función para dos líneas de producción impactadas. Como le número de chocolates en ambas líneas de producción pueden ser grandes, ellos te preguntan como un programador de ACM que calcules la Función Absoluta del Chocolate para esas dos líneas de producción.
Charlie works at the Association of Chocolate Making (ACM) as a manager of one of its factories. Recently, a strange phenomenon is affecting the quality of the chocolates produced by the factory. Oddly, the phenomenon increases the quality of all the chocolates produced in exactly two production lines: A and B. Charlie, as the good manager he is, wants to take advantage of this phenomenon to improve the quality of the chocolates as much as possible. The scientists of ACM have discovered the function that rules the phenomenon: The Absolute Chocolate Function (abbreviated as ACF). This function equals the sum of the absolute differences between each individual chocolate quality Ai from production line A paired with each individual chocolate quality Bj from production line B. Mathematically, the Absolute Chocolate Function can be expressed (using 1-based indexing) as follows:



Now, the scientists need to evaluate the function for the two impacted production lines. As the number of chocolates on both productions lines can be very big, they ask you as a programmer of ACM to calculate the Absolute Chocolate Function for these two production lines.

Input specification

The first line contains two integers N (0 < N 105) and M (0 < M 105) representing the number of chocolates in production lines A and B, respectively. The following line contains exactly N space-separated integer numbers Ai (0 < Ai 105) representing the individual quality value of the i-th chocolate from production line A. The following line contains exactly M space-separated integer numbers Bj (0 < Bj 105) representing the individual quality value of the j-th chocolate from production line B.
;jsessionid=CB423A3DA65249D468F9E3A03270B4E9
La primera línea contiene dos enteros N (0 < N 105) y M (0 < M 105) representando el número de chocolates en las líneas de producción A y B respectivamente. La siguiente línea contiene exactamente N enteros separados por espacios Ai (0 < Ai 105) representando la calidad individual del iésimo chocolate para la línea de producción A. La siguiente línea contiene exactamente M enteros separados por espacios Bj (0 < Bj 105) representando la calidad individual del iésimo chocolate para la línea de producción B.
The first line contains two integers N (0 < N 105) and M (0 < M 105) representing the number of chocolates in production lines A and B, respectively. The following line contains exactly N space-separated integer numbers Ai (0 < Ai 105) representing the individual quality value of the i-th chocolate from production line A. The following line contains exactly M space-separated integer numbers Bj (0 < Bj 105) representing the individual quality value of the j-th chocolate from production line B.
;jsessionid=CB423A3DA65249D468F9E3A03270B4E9

Output specification

The output consists of a single line containing the result of evaluating the absolute chocolate function for the given input.
La salida consiste en una sola línea conteniendo el resultado de la función absoluta del chocolate para la entrada propuesta.
The first line contains two integers N (0 < N 105) and M (0 < M 105) representing the number of chocolates in production lines A and B, respectively. The following line contains exactly N space-separated integer numbers Ai (0 < Ai 105) representing the individual quality value of the i-th chocolate from production line A. The following line contains exactly M space-separated integer numbers Bj (0 < Bj 105) representing the individual quality value of the j-th chocolate from production line B.
;jsessionid=CB423A3DA65249D468F9E3A03270B4E9

Sample input

5 5
1 2 3 4 5
1 2 3 4 5

Sample output

40

Hint(s)

Sample Input 2
5 5
1 2 3 4 5
6 7 8 9 10

Sample Output 2
125

Use fast input and output operations.
Sample Input 2
5 5
1 2 3 4 5
6 7 8 9 10

Sample Output 2
125

Use operaciones de lectura/escritura rápidas
Sample Input 2
5 5
1 2 3 4 5
6 7 8 9 10

Sample Output 2
125

Use fast input and output operations.