Problem G
Government Help
Two major banks in our country are knee-deep in troubles. We will call them “Bank A” and “Bank B” – hopefully you understand we absolutely cannot tell you their real names. It might ruin them.
As a logical consequence of their troubles, government comes to rescue them, preparing a set of financial “packages” that will be distributed between these two banks. However, there is one important condition: the packages will be given to the banks one by one and we need to minimize the difference between the amount given to both banks in any particular moment. Otherwise, one of the banks would gain a big advantage over the other.
For example, imagine that we have four packages with the
values of
There is a better solution, with the maximal difference of
Input
The input contains multiple sets of financial packages. Each
set begins with a line containing a single positive integer
Output
For each set of financial packages, output one line containing the order of assignments of packages to the banks, such as the maximal difference is as low as possible. If there are more possible solutions, you may print any of them.
Assignments must be separated by a space, each assignment consists of one number (the package size), one dash character (“-”), and an uppercase letter (“A” or “B”) specifying the bank.
Sample Input 1 | Sample Output 1 |
---|---|
4 100000 110000 120000 150000 3 100000 100000 100000 0 |
100000-A 150000-B 120000-A 110000-B 100000-A 100000-B 100000-A |