LQDFARM - FARMER

Giới hạn
  • Thời gian: 0.219s
  • Bộ nhớ: 1536MB
  • Mã nguồn: 50000 bytes

Ghi chú: Các bài VNOI đã được chuyển qua VNOJ (Thông báo). Đề bài trên VNOI và vn.spoj.com sẽ không được cập nhật nữa. Một số đề bài không chính xác sẽ chỉ được cập nhật trên VNOJ. Bạn vẫn có thể tìm kiếm đề bài trên VNOI.

Link đọc đề trên VNOJ

A farmer has a set of fields, each of which is surrounded by cypress trees. Also, the farmer has a set of strips of land, each of which has a row of cypress trees. In both fields and stri s, between every two cosecutive cypress trees is a single olive tree. All of the farmer’s cypress trees either surround a field or are in a strip and all of the farmer’s olive trees are between two consecutive cypress trees in a field or in a strip.

One day the farmer became very ill and he felt that he was going to die. A few days before he passed away he called his eldest son and told him, “I give you any Q cypress trees of your choice and all the olive trees which are between any two consecutive cypress trees you have chose n .” From each field and from each strip the son can pick any combination of cypress trees. Since the eldest son loves olives he wants to pick the Q cypress trees which will allow him to inherit as many olive trees as possible.

In Figure 1, assume that the son is given Q =17 cypress trees. To maximize his olive inheritance he should choose all the cypress trees in Field 1 and Field 2, inheriting 17 olive trees.

You are to write a program which, given the information about the fields and the strips and the number of cypress trees the son can pick, determines the largest possible number of olive trees the son may inherit.

INPUT

The input file name is farmer.in. The first line contains first the integer Q : the number

of cypress trees the son is to select; then the integer M , the number of fields; and then the integer K , the number of strips. The second line contains M integers N 1 , N 2 ,… N M , : the numbers of cypress trees in  fields. The third line contains K integers R 1 , R 2 ,… R K : the numbers of cypress trees in strips . (0≤Q≤150000, 3≤ Ni≤150, 2<= Ri<= 150)

OUTPUT

The output file name is farmer.out. The file is to contain one line with one integer: the largest possible number of olive trees the son may inherit.

EXAMPLE INPUTS AND OUTPUTS

Input 
17 3 3
13 4 8
4 8 6

Output
17


  • Người up: coder_1340
  • Nguồn bài: IOI 04