Zombie World


Zombie World

Zoya has developed a new game called Zombie World. The objective of the game is to kill all zombies in given amount of time. More formally,
-         N represents the total number of zombies in the current level
-         T represents the maximum time allowed for the current level
-         P represents the initial energy level a player starts with
-         Ei defines the energy of the i-th zombie
-         D defines the minimum energy the player needs, to advance to the next level
When a player energy is greater than or equal to the i-th zombie's energy, the player wins. Upon winning, the player will be awarded with an additional energy equal to the difference between current zombie energy and the player energy.
One unit of time will be taken to complete the fight with a single zombie.
Rules of the game:-
-         At any given time, a player can fight with only one zombie
-         Player is allowed to choose any one zombie to fight with.
Your task is to determine whether the player will advance to the next level or not, if he plays optimally.

Input Format:
The first line contains the number of test cases (K)

Each test case consists of three parts:

1. The total number of zombies (N) and the maximum time allowed (T)
2. Array of size N, which represents the energy of zombies (E)
3. The initial energy level a player (P) and the minimum energy required to advance (D)

Output Format:

Print "Yes" if a player can advance to the next level else print "No".
Constraints:

1<=K<=10
1<=N<=50
1<=Ei<=500
1<=T<=100
1<=D<=2000
1<=P<=500

Sample Input and Output


SNo.InputOutput
1
1
2 3
4 5
5 7

Yes

PROGRAM:
#include<stdio.h>
int main()
{
 int n,t,e[20],i,pe,me,k;
 scanf("%d",&k);
 while(k)
 {
 scanf("%d",&n);
 scanf("%d",&t);
 for(i=0;i<n;i++)
 scanf("%d",&e[i]);
 scanf("%d",&pe);
 scanf("%d",&me);
 if(t<n)
 goto x;
 else
 {
  for(i=0;i<n;i++)
  {
   if(pe>=e[i])
   {
    pe=pe+(pe-e[i]);
   }
  }
 if(pe<=me)
 printf("yes\n");
 else
x: printf("no\n");
 }
 
    k--;
 }
 return 0;
}
OUTPUT: 
1
2 3
4 5
5 7
Yes

You can directly run it on a IDE: https://ide.geeksforgeeks.org/3un9lTbXuV

You can comment your feedback and doubts if any cheers!

Related Link:Bride Hunting


No comments:

Post a Comment

Super Market Problem | TCS Code Vita 2023 - Zone 1 | Super Market TCS Code Vita 2023 Solution | Code Vita 2023 | Code Vita 2023 season 11 solution

 Problem Description: In a Super market we will find many variations of the same product. In the same way we can find many types of rice bag...