An agent is works between `n`

producer and `m`

consumers. `i`

th producer, generates `s_i`

(product like candy) candy and `j`

th consumer consumes (like eat!) `b_j`

candy in this year. For each candy that sales, agent get `1`

dollar payoff. For some problems, one strict rule was defined that a producer should be sales candy to any producer that the distance between them is not greater than `100`

KM (kilometers). if we have list of all pairs of producer-consumer that the distance between them is lower than `100`

KM, which of the following algorithm is goof for finding maximum payoffs? (suppose `s_i`

and `b_j`

may be becomes very large).

```
1) Maximal Matching
2) Dynamic Programming
3) Maximum Flow
4) 1 , 3
```

one User ask it here:

A Dynamic Programming or Graph Algorithm, a Nice Questions

but i think the answer is false. i need the expert man who help whole competitor.

### Answer1:

A good solution is the one that uses a maximum flow. The graph is constructed as follows: the left part corresponds to the producers and the right part - to the consumers. There should an edge from the source vertex to each of the producers with s_i capacity. There should also be an edge from each consumer to the sink node with b_j capacity. And there should be an edge of an infinite capacity between a producer and a consumer if they are located close to each other. The answer is the size of the maximum flow from the source to the sink. It possible to find the maximum flow in polynomial time(it is a polynomial of the number of consumers and producers) regardless of the values of s_i and b_j.

A solution with a maximum matching is bad because it requires (sum of s_i and b_j) edges. It is not feasible if s_i and b_j are big.

A dynamic programming solution is not good because it is likely that there is no polynomial dynamic programming solution at all.