15,745,506 members
See more:
Asha and Amar are playing SpaceKings a video game. It is a two-player game where the second player is the helper. Asha needs your help maximizing her gold while playing her favorite game. Both are facing N aliens. Asha and Amar are both at a single location and the aliens are lined up in front of them. Asha and Amar take turns shooting the aliens, and she goes first. During her turn, Asha may choose any alien to shoot at (this means Asha may choose to skip a turn). During his turn, Amar always shoots the alien closest to him to help Asha maximize her gold. Asha and Amar can not shoot dead aliens.

If Asha shoots at an alien, its hit points are reduced by P. If Amar shoots at an alien, its hit points are reduced by Q. If an alien’s hit points go below 1, it is killed. The ith alien starts with Hi hit points. Asha is awarded Gi gold if her shot kills the ith alien, but none if Amar’s shot kills it. What is the maximum amount of gold Asha can obtain?

Input:

Each case begins with one line containing three space-separated integers representing P, Q and N. N lines then follow, with the ith line containing two space-separated integers representing Hi and Gi. The aliens are given in the order of their distance from Asha and Amar. In other words, Amar will shoot at the ith alien only if all aliens < i are dead.

Output - The maximum amount of gold that Asha can get

Input

20 60 3

80 100

80 200

120 300

Output - 500

my code passing only 12 test case but totally 14 test case are there what mistake i made in this code can any one help me out to pass all the test case

What I have tried:

My Code

Python
```def main():
inputString = input("")
inputList = inputString.split(" ")
ashaShot, amarShot, n = int(inputList[0]), int(
inputList[1]), int(inputList[2])

hp = []
gold = []
for i in range(n):
hpThis, goldThis = input("").split()
hp.append(int(hpThis))
gold.append(int(goldThis))

def dp(origHp, currAsha):
if(all([i == 0 for i in origHp])):
return currAsha
firstAmarIndex = 0
for index, i in enumerate(origHp):
if(i > 0):
firstAmarIndex = index
break
# firstTemp = hp[firstAmarIndex]
origHp[firstAmarIndex] = max(0, origHp[firstAmarIndex] - amarShot)
maxAns = 0
tempHp = origHp[:]
for index, i in enumerate(origHp):
if(i == 0):
continue
if(i <= ashaShot):
temp = tempHp[index]
tempHp[index] = 0
maxAns = max(maxAns, gold[index] + dp(tempHp[:], currAsha))
tempHp[index] = temp
else:
temp = tempHp[index]
tempHp[index] -= ashaShot
maxAns = max(maxAns, dp(tempHp[:], currAsha))
tempHp[index] = temp

maxAns = max(maxAns, dp(tempHp[:], currAsha))

return maxAns

maxAns = 0
# asha takes a random shot
tempHp = hp[:]
for index, i in enumerate(hp):
if(i <= ashaShot):
temp = tempHp[index]
tempHp[index] = 0
maxAns = max(maxAns, dp(tempHp[:], gold[index]))
tempHp[index] = temp
else:
temp = tempHp[index]
tempHp[index] -= ashaShot
maxAns = max(maxAns, dp(tempHp[:], 0))
tempHp[index] = temp

# asha skips her turn
maxAns = max(maxAns, dp(tempHp[:], 0))
print(maxAns)

main()```
Posted
Updated 20-Dec-20 4:02am
v5
Richard MacCutchan 20-Dec-20 3:19am
Member 15025775 20-Dec-20 3:47am
Code moved to question ...
Patrice T 20-Dec-20 3:24am
Show what you have done.
Richard MacCutchan 20-Dec-20 3:53am
OK, now we can see the code, what is the question? And please use the Improve question link above as requested, for any additional information.
Patrice T 20-Dec-20 10:08am
"my code passing only 12 test case but totally 14 test case are there"
Does you code fail because of time limit or because of wronf result ?

## Solution 1

Development consists of several phases: Design, implementation, testing, debugging, documentation, release. You appear to have skipped the first and rushed into the second, then moved to the third and stopped.

Debugging is part of teh job: when you code runs but doesn't work:
Quote:
my code passing only 12 test case but totally 14 test case are there what mistake i made in this code can any one help me out to pass all the test case
It it part of the job to fix it.

And since we have no idea what the test cases are, let alone which of them you are failing we cannot do that for you even if we wanted to.

So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. How you use it depends on your compiler system, but a quick Google for the name of your IDE and "debugger" should give you the info you need.

Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!