Slippers Selling

Slippers Selling

An indigenous community produces jute slippers and created a website to sell the production online. Slippers are of only one type, but they are produced in various sizes. The stock can be seen as a table with a single row, in which each column (1-base index) represents a size and a number in column - amount of slippers of that size. When a slipper is sold, the stock must be updated. If the stock for a size of slippers have zero value, slippers of this size cannot be sold. That is, the sale is not carried out.

Given the initial inventory and the list of customer orders (sizes), write a program to determine how many slippers are actually sold in total. Each order means size and refers to a single slipper. The Sales are processed sequentially, in the order in which the orders were placed. If a sale it is not possible due to lack of stock, the corresponding order is ignored.

Input: Two arguments. Both are lists of integers (ints).

Output: Integer.

Examples:

assert calc_selling([4, 2, 0, 3, 2], [1, 3]) == 1
assert calc_selling([1, 3, 2, 5], [3, 3, 3, 4]) == 3
assert calc_selling([0, 0, 0], [1, 2, 3]) == 0
assert calc_selling([1, 5, 5], [1, 1, 2, 2, 3, 3]) == 5