| ||You are playing a card game.
In the card game, each card holds a magic spell with two properties: its level and its damage.
During the game, you will play some of the cards (possibly none or all of them) to attack your enemy.
Initially, there are n cards.
The cards are placed in a row and they are labeled from 0 to n-1, in order.
You are given two ints: level and damage.
For each i, the level of card i is level[i], and its damage is damage[i].
In each turn of the game, you can do one of two possible actions:
After each turn, the cards are relabeled 0 through x-1, where x is their current count.
Let L be the level and D the damage of the card that is currently the leftmost card in the row.
If there are at least L cards in the row, you may play the leftmost card.
Playing it deals D damage to your enemy.
After you play this card, the first L cards in the row (including the played one) are discarded.
That is, the cards currently labeled 0 through (L-1), inclusive, are discarded.
The order of the remaining cards does not change.
If you have at least one card, you can take the last card in the row and move it to the beginning.
For example, if the row initially contained cards A,B,C,D,E, in this order, after this operation it will contain E,A,B,C,D.
Return the maximal total damage you can deal to your opponent.
|Method signature:||int maxDamage(int level, int damage)|
|(be sure your method is public)|
|-||level will contain between 1 and 50 elements, inclusive.|
|-||level and damage will contain the same number of elements.|
|-||Each element in level will be between 1 and 50, inclusive.|
|-||Each element in damage will be between 1 and 10,000, inclusive.|
|You can play card 0 three times in a row, dealing 10+20+30 = 60 damage.|
|Here, it is optimal to start by moving the last card to the beginning of the row.
In the second turn we then use the card and deal 30 damage.
Afterwards, all three cards are discarded.|
|This time you can't use any spell card.|
|You can use 2 cards with damage 20 and 40.|
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.