Time limit
2s
Memory limit
128 MB
There are N empty boxes in a row, and you want to place M books into them in order. The boxes are numbered from 1 to N, and the books are numbered from 1 to M. At the beginning, you stand in front of box 1 while holding book 1.
The placement process is as follows.
The capacity of box i is Ai, and the size of book j is Bj. A book fits in the current box if the sum of the sizes of the books already in that box plus the size of the current book does not exceed the box capacity.
After performing the process exactly as described, compute the total wasted capacity over all boxes. The wasted capacity of one box is its capacity minus the total size of the books placed in it.
You may not change the order of the boxes or the books given in the input.
The first line contains the number of boxes N and the number of books M. The second line contains the box capacities A1, A2, ..., AN. The third line contains the book sizes B1, B2, ..., BM.
Print the total wasted capacity over all boxes on the first line.