Buying Books 2
Time limit1sMemory limit256 MB
Find the maximum number of book copies N buyers can purchase from M stores under per-pair purchase limits.
- Level
Medium4 of 10
- Topics
- Graph
- Solved
- No attempts yet
Problem
N people want to buy the same book. The people are numbered 1 to N, and person j wants copies. M online stores sell the book. The stores are numbered 1 to M, and store i holds copies.
These N people are the only buyers, and the total number of copies the stores hold equals the total number of copies the people want.
How many copies one person buys from one store is limited. Person j can buy at most copies from store i. Given every purchase limit between a store and a person, write a program that finds the largest number of copies that can be bought.
Input
The first line contains the number of people N and the number of online stores M. ()
The second line contains , the number of copies each person wants. ()
The third line contains , the number of copies each store holds. ()
Each of the next M lines contains N numbers and gives the purchase limits. The j-th number on the i-th line is , the largest number of copies person j can buy from store i. ()
holds.
Output
Print the largest number of copies that can be bought.