This page is still under construction.

Parts of this page are still being built. What you see may change.

Searching for Sogang's History

Interview

Time limit1sMemory limit1024 MB

Summary
Given current and freshman-era facility scores for campus places, find the largest increase in total score from restoring at most one place.
Level

Easy2 of 10

Topics
Implementation, Array
Solved
No attempts yet

Problem

When Seonghyeon (dart) was a freshman, the campus looked very different. For example, the cafeteria was not only in Woojeong Hall but also in Emmaus Hall. Seogang Sikgaek had a Popeyes, and across from Kim Daegeon Hall (K Hall), the stately Gepert Nam Deok-woo Economics Hall (GN Hall) was a run-down student union building (C Hall). The campus did not get any bigger, but the facilities in many of its buildings changed.

Seonghyeon thought that some places on campus now had better facilities than before, but others had worse ones. He wished he could restore the facilities at some of these places to what they were when he was a freshman. So he stood in front of the statue of Father Gepert, the founder of Sogang University, and prayed that the facilities at certain places on campus would be returned to what they were when he entered.

Thirty days after the prayer, Father Gepert suddenly appeared like a mirage. He said that if Seonghyeon chose at most one place on campus, he would restore the facilities there to what they were when Seonghyeon was a freshman. If Seonghyeon chose a place that currently has facilities, those facilities would be replaced with the ones that were there when he was a freshman.

Seonghyeon had prepared for this. For each facility on campus, he had assigned a score for the place as it is now and a score for the facility that was there when he was a freshman. Because of this, he could tell Father Gepert which place he wanted to restore without hesitating for even a second.

Seonghyeon chose at most one place to restore in order to maximize the total score of all places on campus. Find the increase in the total score.

Input

The first line contains the number of places that currently have facilities, NN, and the number of places that had facilities when Seonghyeon was a freshman, MM. (1≤N,M≤1 0001 \le N,M \le 1\,000)

The second line contains the scores a1,a2,⋯ ,aNa_1, a_2, \cdots, a_N that Seonghyeon assigned to the NN places that currently have facilities, in order. (1≤ai≤1 0001 \le a_i \le 1\,000)

The third line contains the scores b1,b2,⋯ ,bMb_1, b_2, \cdots, b_M that Seonghyeon assigned to the MM places that had facilities when he was a freshman, in order. (1≤bi≤1 0001 \le b_i \le 1\,000)

The current score of place ii is aia_i if i≤Ni \le N, and 00 otherwise, since there is no facility there. Likewise, the freshman-era score of place ii is bib_i if i≤Mi \le M, and 00 otherwise, since there was no facility there.

Output

On the first line, print the increase in the total score caused by Seonghyeon's choice.

Examples3

  1. Example 1

    Input
    5 5
    1 2 3 4 5
    5 4 3 2 1
    
    Expected output
    4
    
  2. Example 2

    Input
    5 6
    1 2 3 2 1
    2 2 2 2 2 10
    
    Expected output
    10
    
  3. Example 3

    Input
    5 3
    1 2 3 2 1
    1 1 3
    
    Expected output
    0