Buffcraft
InterviewTime limit2sMemory limit256 MB
Pick at most k direct and percentage buffs so the boosted base times the percentage multiplier is as large as possible.
- Level
Easy3 of 10
- Topics
- Sorting, Greedy, Brute force
- Solved
- No attempts yet
Problem
Brenda plays the role playing game Buffcraft. Shields, swords, books and other carried items do not change a character's stats in Buffcraft. The only way to raise a stat is to buff the character.
Buffcraft has two kinds of buffs. A direct buff raises the base value of a stat, and a percentage buff raises the stat by a fraction of that base value. To be precise, if the unbuffed base value of a stat is and the character carries direct buffs of strength together with percentage buffs of strength , the resulting stat equals . The resulting stat can be fractional.
A character has only buff slots. If more than buffs are applied, only the last stay active, so there is no reason to apply more than buffs at once. The same buff cannot be applied twice.
Brenda is about to send her character on a raid and wants its health as high as possible. Choose the set of buffs that gives the maximum total health.
Input
The first line contains four integers , , , : the base health of the character, the number of buff slots, the number of available direct buffs, and the number of available percentage buffs.
The second line contains integers , the strengths of the direct buffs.
The third line contains integers , the strengths of the percentage buffs.
Every number in the input is at least 0 and at most 50000. If or is 0, the matching line is empty.
Output
Print on the first line the number of direct buffs and the number of percentage buffs to apply (, , ).
Print on the second line the indices of the chosen direct buffs in increasing order. Buffs are numbered from 1.
Print on the third line the indices of the chosen percentage buffs in increasing order.
If or is 0, print an empty line in its place.
Several sets of buffs can reach the maximum health, so print the set that the following rule selects.
- Sort the direct buffs by decreasing strength, putting the smaller index first when two strengths are equal. Sort the percentage buffs the same way.
- For each from to , set and take the first direct buffs and the first percentage buffs of those sorted orders.
- Among these candidates print the one with the largest resulting health. If several candidates give the same health, print the one with the smallest .