1962: [USACO 2022 US Open Contest Bronze] Problem 3. Alchemy
题目描述
Always keen to learn new hobbies, Bessie the cow is learning how to transform metals. She has ai (0≤ai≤104) units of metal i for 1≤i≤N≤100. Furthermore, she knows K (1≤K<N) recipes where she can combine one unit each of several metals to make one unit of a metal with a higher number than all constituent metals. It is additionally guaranteed that for each metal, Bessie knows at most one recipe to make it.
Compute the maximum number of units of metal N Bessie can possibly have after some series of transformations.
输入
输出
样例输入
5
2 0 0 1 0
3
5 2 3 4
2 1 1
3 1 2
样例输出
1
提示
In this example, the following is an optimal series of transformations: 1. Transform one unit of metal 1 into metal 2.
2. Transform one unit of metal 2 into metal 3.
3. Transform one unit of metal 3 and metal 4 into metal 5.
Now Bessie is left with one unit of metal 1 and one unit of metal 5. She cannot form any additional units of metal 5.