#B4051. Maximizing Weapon Proficiency

    ID: 11708 Type: Default 1000ms 256MiB

Maximizing Weapon Proficiency

Maximizing Weapon Proficiency

Little Yang owns n different weapons. For each weapon i (1 ≤ i ≤ n), his initial proficiency is given by \(c_i\). He will participate in m battles sequentially. In each battle he must choose exactly one weapon to use. If he uses weapon i in the j-th battle and its proficiency before that battle is \(c'_i\), then after the battle, its proficiency becomes \(c'_i + a_j\). Note that \(a_j\) can be positive, zero, or negative, which means that using a weapon in a battle may increase, not change, or even decrease its proficiency.

Little Yang wants to know how to choose his weapons such that after all m battles, the maximum proficiency among all his n weapons is as large as possible. Solve this problem.

inputFormat

The input consists of three lines. The first line contains two integers (n) and (m), representing the number of weapons and the number of battles, respectively. The second line contains (n) integers (c_1, c_2, \dots, c_n) representing the initial proficiency for each weapon. The third line contains (m) integers (a_1, a_2, \dots, a_m), where each (a_j) is the proficiency change for the weapon used in the (j)-th battle.

outputFormat

Output a single integer, which is the maximum possible proficiency among all weapons after making an optimal choice for all battles.

sample

3 5
3 1 2
2 -1 3 -2 0
8