The leaders of AC country made a decision to regain the TW Island. But they have to face the powerful force from USB. So the leaders have to hire some excellent soldiers from the training base called ALPC to format the most powerful force.
The followings are the consists of ALPC:
1. There are more than one alpcs who are generals, like alpc04.
2. Every alpc has a direct superior, except the generals.
3. The alpc who has underling is an officer (Every officer’ number is no more than 500, like alpc21, alpc32).
4. If send one alpc to the war, so will his direct superior. Of course the general’s direct superior is himself.
5. Every alpc has two values. Vi is the fighting strength and Ci is the cost that the leader have to pay for the soldier.
Due to the AC country has limited financial resources, the leaders want to format the most powerful force with the cost not exceed G. Obviously, it is an uphill task! Therefore, the leaders of the AC country have assigned the task to alpc72 because of the outstanding behavior he had done at the ACM/ICPC. But alpc72 has been lost in hunting PLMM nowadays, so that he has no time to deal with this problem. What’s more, he left it to you.