Beer Pong

This game is very famous among college students in western countries. In this game there are a specified number of balls which the players throw into glasses of beer from a distance. Both the teams have got same number of chances of throwing. A penalty is there for every missed chance. Now that two teams have got into the US finals of Beer Pong and both the teams are really skilled ones, there is no chance that any chance would be missed.

Now to decide the winner the organizers added a twist. The total points scored will be the product of all the balls in k beer glasses. This is not their field. So both the teams are in a great worry as their pride is at stake. Now its jus a coincidence that I have got friends in both the teams and so can’t give unfair advantage to any team. In the mean time I have to help them out. So here is the thing I told them that I would provide them the maximum points that is achievable to which both parties agreed. Now just do this for me.

Input

The input consists of several test cases. Each line of a test case consists of two numbers separated by a space: n (k<=n<=100), the number of balls and k (2<=k<=20), the number of beer glasses.

 

Output

For each input line, determine the maximum number of points achievable.

 

Sample Input

10 3
7 2

 

Sample Output

36
12

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Diagnostics;

 

namespace BeerPong

{

    class Program

    {

        static void Main(string[] args)

        {

            int balls = 52;

            int glass = 50;

            double maxPoints = 1;

            //Create the pointer array

            int[] pointer = new int[glass];

            //Pointer array initialization

            for (int i = 0; i < glass; i++)

            {

                pointer[i] = balls / glass;

            }

            //Filling up remaining balls

            for (int i = 0, j = 0; i < balls%glass; i++)

            {

                if (j < glass)

                {

                    pointer[j]++;

                    j++;

                }

                else

                {

                    j = 0;

                    pointer[j]++;

                    j++;

                }

            }

            for (int i = 0; i < glass; i++)

            {

                maxPoints = maxPoints * pointer[i];

            }

            Console.WriteLine("Maximum number of points achievable = " + maxPoints);

        }

    }

}

Advertisements
This entry was posted in Information Technology. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s