jeudi 13 août 2015

Find maximum damage [on hold]

Our hero Harry Potter is back in action. He is in midst of a fight against The Dark Lord Voldemort. Being a beginner in wizardry, he knows a limited number of spells and the damages they would do to Voldemort.

Here comes the Twist.

Harry knows n attacks 1,2,3,..,n with damages a[1],a[2],...,a[n]. As soon as he selects a particular spell to cast, Voldemort performs some dark magic and disables both the previous and the next attacks of Harry i.e. if Harry selects the ith spell, his i-1th and i+1th spells get disabled automatically.

Only one attack would be disabled in case Harry selects 1st or nth attack.

Harry seeks your help to find out the maximum damage he can cause to Voldemort using all the possible attacks.

Note that, if Harry is not able to do any damage to Voldemort, you need to warn Harry by printing "DANGER".

What algo should be used.

I am trying to find maximum element and remove the adjoining element but that gives wrong answer. Sample Input

2

5 6 5 1 3 4

3

4 10 1

Sample Output

11

10



via Chebli Mohamed

1 commentaire: