Click here to Skip to main content
15,887,175 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
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

Explanation:
Asha should give up the first alien. During her first two turns she should soften up the third alien bringing it down to 80 hp, allowing her to easily get the last shot on the second and the third aliens

Here are some of there other test cases:

Input

50 60 2

40 100

40 90

Output - 100

Input

50 60 2

40 100

40 200

Output - 200

Input

50 100 2

60 100

60 200

Output - 200

Input

50 400 2

60 100

190 200

Output - 0

What I have tried:

it is available in stackoverflow but not running all the test cases
Posted
Updated 15-Jul-20 22:50pm

It appears that you need to model players and aliens. There are two players and N aliens. They need to have the characteristics described in the problem statement. Have them take turns shooting until there are no more aliens alive and you will have your result. By model I mean make a class to represent them. The player class will need a method to "shoot." Aliens will need a method to call when they are shot to adjust their health level and one to tell you what their level of health is.

What more is there to it?

and, no, I will not write any code for you. That's your job.
 
Share this answer
 
We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

We need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did. Just grabbing code from another website and hoping it'll do the job, then asking others to fix it for you is not going to cut it.

Either write your own (recommended) or break out the debugger and find out why the code you took doesn't work. We aren't going to do it for you.
 
Share this answer
 
Give some secret saucage to your code and it will work. One important ingredience is the debugger and second is to write some useful tests or run the problematic code pathes by inputting values to hit them. That what I have done this morning to make my bread and now my code works fine :-O
 
Share this answer
 
Quote:
How do I solve this problem some hidden test cases are not working

You have a secret problem in your secret code, but if I give you the secret magic correction, I will have to kill you. :)
If the help you want is us solving the problem, I fear you will have to wait.
If you want us to help you fix your code, you have to show the code and give as many details as possible on the problem.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900