| Winter Cup 6.0 Online Mirror Contest |
|---|
| Finished |
Rami got tired of working for a low salary. He asked for a raise, but Yessine told him that the best he can do is buy him a new Shisha. Rami got angry and quit the company. Now he wants to get rich quickly. So, he decided to use the knowledge he acquired at Iceberg Corporation and become a cryptocurrency trader.
In fact, the cryptocurrency market has $$$n$$$ currencies. Also, there are $$$m$$$ pairs of currencies that can be exchanged. For each pair $$$(u,v)$$$, there is a rate $$$r_{u,v}$$$ that represents the exchange rate of the currency $$$u$$$ to the currency $$$v$$$. But that exchange is not free, there is a fee $$$f_{u,v}$$$ that is deducted from the exchanged amount according to the following formula: $$$$$$ \mathrm{amount}(v) = r_{u,v}\times (\mathrm{amount}(u)-f_{u,v}) $$$$$$
Rami is broke, but he can still borrow up to $$$x$$$ amount of money of currency $$$0$$$ from Oussama. He wants to know the minimal integer amount of money he should spend so that he can end up with strictly more money by only converting currencies and make a win.
Rami can exchange currencies as many times as he wants. But, the final amount must be in the currency $$$0$$$.
Formally, let $$$z_1$$$ be the amount that Rami has borrowed from Oussama expressed in currency $$$0$$$, and let $$$z_2$$$ be the amount that he got after the series of conversions, and expressed in currency $$$0$$$ as well. Rami will make a win if and only if $$$\Delta z= z_2-z_1 \gt 0$$$
The first line contains three integers $$$n,m,x,$$$ with $$$1\le n\le 500,$$$ $$$1\le m \le 4000$$$ and $$$0\le x \le 10^9$$$
The next $$$m$$$ lines contain each $$$4$$$ numbers $$$u_i,v_i,r_{u_i,v_i},f_{u_i,v_i}$$$ with:
Output $$$M:$$$ The minimum integer amount he needs to borrow so that he can make a win. If it is impossible to win any amount of money or Rami needs to borrow more than $$$x$$$, output $$$-1$$$
2 2 10001 2 1.01 10.002 1 1.01 10.00
-1
3 4 50001 2 0.70 1.002 1 1.60 1.001 3 0.80 5.003 1 2.00 5.00
23
5 5 10001 2 1.00 1.002 3 1.00 1.003 4 1.00 1.004 1 1.00 1.001 5 10.00 0.00
-1
4 12 10000000001 3 0.61 5.741 2 1.35 8.861 4 0.85 6.002 4 0.61 8.232 3 0.69 9.452 1 0.50 8.713 2 1.46 5.043 4 1.36 8.003 1 0.73 9.894 3 0.85 8.344 2 0.54 5.994 1 1.43 9.60
72
| Name |
|---|


