当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

2791:Government Help

Special Judge 特殊评判
题目描述
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 100 000, 110 000, 120 000, and 150 000. If we give the first package to the Bank A, then the second one to the Bank B, the third one to the Bank B, and the fourth package to the Bank A, the difference between the help provided to the banks will be +100 000 after the first package, -10 000 after the second one, -130 000 after the third one, and +20 000 after the last package. The maximal difference is therefore 130 000.

There is a better solution, with the maximal difference of 100 000 only: first, give 100 000 to the Bank A, then 120 000 to the Bank B, then 110 000 to the Bank A, and then 150 000 to the Bank B.
输入解释
The input contains multiple sets of financial packages. Each set begins with a line containing a single positive integer N: the number of financial packages (1 ≤ N ≤ 50 000). The second line is a set of N positive integers separated by a space, all of them between 100 000 and 199 999 inclusive. These numbers specify the amount of money in individual packages. Packages can be assigned in any order, the order of numbers on the second line is therefore not important.

The last set will be followed by a line containing single zero.
输出解释
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.
输入样例
4
100000 110000 120000 150000
3
100000 100000 100000
0
输出样例
100000-A 120000-B 110000-A 150000-B
100000-B 100000-A 100000-A
来自杭电HDUOJ的附加信息
Recommend lcy

该题目是Virtual Judge题目,来自 杭电HDUOJ

题目来源 CTU Open 2008

源链接: HDU-2791

最后修改于 2020-10-25T22:56:48+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
2000/1000MS(Java/Others) 32768/32768K(Java/Others)