Pay for Phones!
Description
You are given prices of 4 different mobile phones and also provided with the number of each of the phones that you need to buy.
You have with you 150000 units of money. Comment if it is possible to buy those phones or not.
Input
Input Format :
First line contains 4 space separated positive values which are prices of the 4 mobile phones respectively.
Second line contains the quantity/count of each mobile phones that you need to buy
Constraints :
price of each phone < 100000
Output
Output "Possible" (without quotes) if it is possible to buy desired numbers of mobile phones.
Else in all other case, print "Not Possible" (without quotes)
Sample Output 1
Not Possible
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[] price =new int[4];
int[] number =new int[4];
for (int i =0; i<=3;i++){
price[i]= sc.nextInt();
}
for (int i =0; i<=3;i++){
number[i]= sc.nextInt();
}
int sum=0;
for (int i =0; i<=3;i++){
sum=price[i]*number[i]+sum;
}
if(sum>150000){
System.out.println("Not Possible");
}else {
System.out.println("Possible");
}
}
}
No comments:
Post a Comment