you n package try place box package box there m supplier produce box different size infinite supply a package place box size package equal size boxthe package size give integer array package packagesi size ith package the supplier give 2D integer array box boxesj array box size jth supplier producesyou want choose single supplier use box total waste space minimize for package box define space waste size box size package the total waste space sum space waste boxesFor example fit package size 235 supplier offer box size 48 fit package size2 size3 box size4 package size5 box size8 this result waste 42 43 85 6return minimum total waste space choosing box supplier optimally 1 impossible fit package inside box since answer large return modulo 109 7 Example 1input package 235 box 4828output 6explanation it optimal choose supplier size4 box size8 boxthe total waste 42 43 85 6example 2input package 235 box 142334output 1explanation there box package size 5 fit inexample 3input package 358101112 box 1211910514output 9explanation it optimal choose supplier size5 box size10 box size14 boxesThe total waste 53 55 108 1010 1411 1412 9 Constraintsn packageslengthm boxeslength1 n 1051 m 1051 packagesi 1051 boxesjlength 1051 boxesjk 105sumboxesjlength 105the element boxesj distinct