## COCI '18 Contest 6 #4 Simfonija

View as PDF

Points: 15 (partial)
Time limit: 0.6s
Memory limit: 64M

Problem types
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

Almost no one believed in the virtuous abilities of the composer Marin. Specifically, not until the day he composed his 9th symphony.

The symphony can be represented as a series of frequencies that are integer numbers. In order for Marin to prove his talent and demonstrate that this symphony is not just one of many, he decided to compare it with the ancient symphony "Little Night Fiesta" of the best musician in history, Stjepan. In the stars it is written that the lengths of these two symphonies are equal to .

Marin compares the symphonies by writing them one under the other to a piece of paper. The symphony diversity is defined as the sum of the absolute differences of the corresponding frequencies. The diversity of symphonies and of length is:

Before comparing the two symphonies, Marin will do two things. First, he will modulate his symphony by adding an integer number to each frequency. Then he will change no more than frequencies to some other arbitrary frequency value because he had a vision in the dream as well as every top author.

Marin will choose and change some frequencies so that his symphony is as similar to Stjepan's, i.e. so the defined diversity is minimal. Help Marin and calculate the smallest possible diversity to Stjepan's symphony.

#### Input

In the first line there are integer numbers and , numbers from the task's text.

In the second line there are integers which represent frequencies of Marin's symphony.

In the third line there are integers which represent frequencies of Stjepan's symphony.

#### Output

In the only line print out the smallest possible diversity between Marin and Stjepan's symphony.

#### Scoring

In the test samples totally worth 40% of the points it will hold .

#### Sample Input 1

3 0
1 2 3
4 5 7

#### Sample Output 1

1

#### Sample Input 2

3 1
1 2 3
4 5 7

#### Sample Output 2

0

#### Explanation for Sample Output 2

If Marin modulates his symphony for and changes the last frequency to , his symphony will then be completely equal to Stjepan's, so the required diversity is .

#### Sample Input 3

4 1
1 2 1 2
5 6 7 8

#### Sample Output 3

2
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.42360666394233704, "perplexity": 5540.219637564041}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2020-29/segments/1593655924908.55/warc/CC-MAIN-20200711064158-20200711094158-00487.warc.gz"}