P/W:

Profit:

Total Profit:

pseudo-code:

  while (bag_weight > 0) {

  index = find_max_element_index

   if(bag_weight > weight_arr[index]) {

   bag_weight -= weight_arr[index]

  total_profit += profit_arr[index]

   } else {

     total_profit += (bag_weight / weight_arr[index]) * profit_arr[index]

  }