Abhay is playing a shooting game. There are n balloon arranged in a row. Each balloon has a number written on it and Abhay can burst balloons from beginning or end. Abhay is really fond of number k and wants to make the sum of all the balloons remaining equal to k. For busting 1 balloon 1 unit of energy is spent by Abhay. He wants to find the number of ways in which he can make the sum of balloons equal to k. But he is not willing to spend a lot of energy. So you also have to tell the minimum energy that he has to spend to make the sum equal to k
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
int n,k;
System.out.println("Enter number of ballons: ");
Scanner in =new Scanner(System.in);
n=in.nextInt();
System.out.println("Enter value of k: ");
k=in.nextInt();
int arr[][] = new int[2][];
arr[0] = new int[n];
arr[1] = new int[k];
int count = 0;
for (int i = 0; i < arr.length; i++)
for (int j = 0; j < arr[i].length; j++)
arr[i][j] = count++;
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[i].length; j++)
System.out.print(arr[i][j] + " ");
System.out.println();
}
}
}
Comments
Leave a comment