let denote follow function f this function take array length n return array initially result array for integer 1 n add element a_i end result array great previous element formally a_i maxlimits_1 le j ia_j some example function f 3 1 2 7 7 3 6 7 8 fa 3 7 8 1 fa 1 4 1 1 2 3 fa 4 1 3 1 2 6 8 7 7 4 11 10 fa 1 3 6 8 11 you give array array a_1 a_2 dots a_n array b_1 b_2 dot b_m you delete element array possibly zero to delete element a_i pay p_i coin value p_i negative p_i coin delete element Calculate minimum number coin possibly negative spend fulfil equality fa b