Falling Stocks. Bankrupted companies. Banks with no Cash. Seems like the best time to invest: ``Think I'll buy me a football team!"
No seriously, I think I have the solution to at least the problem of cash in banks. Banks nowadays are all owing each other great amounts of money and no bank has enough cash to pay other banks' debts even though, on paper at least, they should have enough money to do so. Take for example the inter-bank loans shown in figure (a). The graph shows the amounts owed between four banks (A ...D). For example, A owes B 50M while, at the same time, B owes A 150M. (It is quite common for two banks to owe each other at the same time.) A total amount of 380M in cash is needed to settle all debts between the banks.
In an attempt to decrease the need for cash, and after studying the example carefully, I concluded that there's a lot of cash being transferred unnecessarily. Take a look:
I have data about inter-bank debts but I can't seem to be able to process it to obtain the minimum amount of cash needed to settle all the debts. Could you please write a program to do that?
Your program will be tested on one or more test cases. Each test case is specified on N + 1
$N < 1, 000$
-->
N < 1, 000
$N \times N$
-->
N×N
k
.
B
A
where k
is a space character, B
4
0 50 100 0
150 0 20 0
0 0 0 30
30 0 0 0
0
1. 380 120
Migrated from old NTUJ.
Arab & North Africa 2008
No. | Testdata Range | Score |
---|