Halloween
Limits: 2 sec., 256 MiB
This statement was translated automatically from Ukrainian. In case of any discrepancy, the Ukrainian version is authoritative.
Zenyk and Marichka were visited by their old friend Andriy on Halloween. The official reason for his visit is to catch up and just chat with them. However, Zenyk and Marichka are well aware of Andriy’s true intentions — he just wants to get some candy from his friends.
Zenyk and Marichka each have a bag of candy. In total, Zenyk’s bag contains \(n\) candies, with the \(i\)-th candy costing \(a_i\) hryvnias. Similarly, Marichka’s bag contains \(m\) candies, and the price of the \(i\)-th candy is \(b_i\) hryvnias. They want to give Andriy two candies — one from Zenyk’s bag and one from Marichka’s bag.
Being quite greedy, they are only willing to give Andriy the cheapest candies. That is, they will choose the cheapest candy from the first bag and the cheapest candy from the second bag. What will be the total value of the gift received by Andriy? In other words, find the sum of the values of the two candies that Andriy will receive.
Input
The first line contains two integers \(n\) and \(m\) — the number of candies in Zenyk’s and Marichka’s bags, respectively.
The second line contains \(n\) space-separated integers. They describe the values of Zenyk’s candies.
The third line similarly describes Marichka’s \(m\) candies.
Output
In a single line, output a single integer — the value of the gift that Andriy will receive.
Constraints
\(1 \le n, m \le 100\),
\(1 \le a_i, b_i \le 1000\).
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| 4 7 4 3 2 7 5 2 1 7 6 4 1 | 3 |
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|