Line 1
|
B N, where B is the energy of Bob and N is the number of Zombie |
Line 2
|
Zi, where Zi is a list containing energy of zombies separated by space |
Constraints:
1<=B<=10^9
1<=Zi<=10^5
for this problem all the divisions are integer divisions.
Line 1 | For Valid Input,print YES Or NO For Invalid Input,print Invalid Input |
Sample Input and Output
SNo. | Input | Output |
---|---|---|
1 | 35 3 5 9 6 |
YES |
2 | 456 68 a |
Invalid Input |
3 | 4 4 1 3 2 4 |
NO |
//program
import java.io.*;
public class Zombie_World
{
public static void main(String args[])
{
try
{
int NumberOfZombies;
int zEnergies[];
String energies,result[], en[],EnergiesOfZombie;
boolean flag=true;
double BobEnergy,res;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
energies=br.readLine();
result=energies.split(” “);
BobEnergy=Double.parseDouble(result[0]);
NumberOfZombies=Integer.parseInt(result[1]);
zEnergies=new int[NumberOfZombies];
EnergiesOfZombie=br.readLine();
en=EnergiesOfZombie.split(” “);
for(int i=0;i<NumberOfZombies;i++)
{
zEnergies[i]=Integer.parseInt(en[i]);
res=(zEnergies[i]%2)+(zEnergies[i]/2);
BobEnergy=BobEnergy-res;
if(BobEnergy<0)
{
flag=false;break;
}
}
if(flag)System.out.print(“YES”);
else System.out.print(“NO”);
}
catch(NumberFormatException e)
{
System.out.print(“Invalid Input”);
}
catch(Exception e)
{
System.out.print(“Error”);
}
}
}