#
WC 8.1 SOMEONE HELP AMOL TO SHOP!

Amol wants to buy a watch and a phone cover from his favorite electronics store. The store has several models of each. Amol wants to spend as much as possible for the 2 items, given his budget.

Given the price lists for the store's watch and phone covers, and Amol's budget, find and print the amount of money Amol will spend. If he doesn't have enough money to both a watch and a phone cover, print -1 instead. he will buy only the two required items.

For example, suppose he has b=60 to spend. Three types of watches cost watches=[40,50,60]. Three phone covers cost pcovers=[5,8,12]. he could purchase a 40watch +12 phone covers=52 or 50watch + 5phone cover=55 or 50 watch + 8 phone covers=58. he chooses the latter. he can't buy more than 2 items so he can't spend exactly 60

return the maximum total price for the two items within Amol's budget, or -1 if he cannot afford both items. .

INPUT:

The first line contains three space-separated integers b,n , and m, his budget, the number of watch models and the number of phone cover models.

The second line contains n space-separated integers watches[], the prices of each watch model. The third line contains m space-separated integers pcovers[] , the prices of the phone covers.

OUTPUT

Print a single integer denoting the amount of money Amol will spend. If he doesn't have enough money to buy one watch and one phone cover, print -1 instead.

EXAMPLE:

INPUT

10 2 3

3 1

5 2 8

OUTPUT

9

EXPLANATION

he can buy the 2nd watch and the 3rd phone cover for a total cost of 8+1=9 .

tescaselink

### This challenge is worth 60 points.

### You must be logged in to submit a solution

View ranklist for this challenge

About scoring and submission