AT001 - EDITORIAL

PROBLEM: AT001

DIFFICULTY: Easy

PREREQUISITES: Math

QUICK EXPLANATION:

Two players ‘A’ and ‘B’ are playing a game. They were given N number of coins where ‘N’ is even and they will get alternative turns in which player can select a coin from one of the end.Whenever a coin is selected ,it is excluded from the list of coins. The winner is the player with maximum amount of sum. At what position first or second does player ‘A’ need to start the game in order to win the game and how much ‘A’ can collect starting at that position.

EXPLANATION:

The program is divided into different functions to make the logic more understandable.

Arrays:

int A[] - This integer array STORES the values of all the coins where the number of elements in the array is the number of coins(N).

Functions:

int getvalue(int arr[],int start,int end): This function takes the array which stores the values of coins and two integer values which points start and end location of the coins list among which no coin is selected and returns the sum of the values of the coins.
int max(int a,int b):Upon taking two integer values this function return the value of the integer which is larger.
int min(int a,int b):Upon taking two integer values this function return the value of the integer which is smaller.

Solution:
click here to see the solution