Fighting Against Monsters
시간 제한5초메모리 제한256 MB
매초 커지는 피해량 1, 2, 3, ...을 세 몬스터에 배분해 받는 총 피해를 최소로 만든다.
문제
One day, a hero and three monsters, one of which is the boss with extremely high health points, are fighting in the forest through turn-based battles. The health points of the three monsters are , and respectively, and their attack values are , and respectively.
During the -th second, the hero will be attacked by monsters at first, and the damage is the sum of attack values of all alive monsters. Then he will select exactly one monster which is still alive and attack it. The selected monster will suffer a damage of value (i.e. its health point will be decreased by ). That is to say, during the -st second, one of these three monsters will be under an attack of damage , during the -nd second, one of them, if alive, will be under an attack of damage , during the -rd second, one of them, if alive, will be under an attack of damage , and so on.
Once the health point of a monster is less than or equal to zero, it will die immediately. The hero will win if all the monsters have been killed.
Now you are asked to develop a strategy to minimize the total damages the hero should suffer before he wins the battle.
입력
There are multiple test cases. The first line of the input contains an integer (), indicating the number of test cases. For each test case:
The first line contains integers , , , , and (, , ).
출력
For each test case, output an integer denoting the minimal total damages the hero should suffer.