# Army Training CodeChef Solution

### We Are Discuss About CODECHEF SOLUTION

Army Training CodeChef Solution

## Army Training CodeChef Solution

Chef is a high-ranked army officer and he has been given the job to train the army.

The army consists of NN soldiers where each soldier has 33 parameters:

• Attack pointsAiAi where (0<Ai<1000)(0<Ai<1000);
• Defense points(1000Ai)(1000−Ai);
• Soldier typeATTACK or DEFENSE.

For the whole army:

• Attack value of the army is defined as the sum of attack points of all ATTACK type soldiers.
• Defense value of the army is defined as the sum of defense points of all DEFENSE type soldiers.
• Rating of the army is defined as the product of Attack value and Defense value of the army.

Assign the soldier type to each of the soldiers to maximize the rating of the army. Print the maximum rating.

NOTE: The output may exceed the range of a 3232-bit integer.
Remember to use 6464-bit data types, such as long long in C++.

### Input Format

• The first line of input will contain a single integer TT, denoting the number of test cases.
• Each test case consists of multiple lines of input.
• The first line of each test case contains an integer NN — the number of soldiers in the army.
• The next line contains the array AA — where AiAi denotes the attack points of the ithith soldier.

## Army Training CodeChef Solution

### Output Format

For each test case, output on a new line the maximum possible rating that can be achieved.

### Constraints

• 1T1001≤T≤100
• 2N10002≤N≤1000
• 0<Ai<10000<Ai<1000
• Sum of NN over all test cases does not exceed 20002000.

### Sample Input 1

4
2
500 500
3
500 500 500
4
100 800 300 500
4
300 700 800 200


### Sample Output 1

250000
500000
2080000
2250000


## Army Training CodeChef Solution

Test case 11: Soldier 11 should be used for ATTACK while soldier 22 should be used for DEFENSE. Thus, the attack value as well as the defense value equals 500500. The rating =500500=250000=500⋅500=250000. It can be proven that this is the maximum possible rating that we can achieve for the given army.

Test case 22:

• Soldier 11 and 22 should be used for ATTACK. So, attack value =500+500=1000=500+500=1000
• Soldier 33 should be used for DEFENSE. So, defense value =(1000500)=500=(1000−500)=500

So, rating =1000500=500000=1000⋅500=500000. This is the maximum possible rating that we can achieve for the given army.

Test case 33:

• Soldier 22 and 44 should be used for ATTACK. So, attack value =800+500=1300=800+500=1300
• Soldier 11 and 33 should be used for DEFENSE. So, defense value =(1000100)+(1000300)=1600=(1000−100)+(1000−300)=1600

So, rating =13001600=2080000=1300⋅1600=2080000. This is the maximum possible rating that we can achieve for the given army.

Test case 44:

• Soldier 22 and 33 should be used for ATTACK. So, attack value =700+800=1500=700+800=1500
• Soldier 11 and 44 should be used for DEFENSE. So, defense value =(1000300)+(1000200)=1500=(1000−300)+(1000−200)=1500

So, rating =15001500=2250000=1500⋅1500=2250000. This is the maximum possible rating that we can achieve for the given army.

## SOLUTION

Yhaa You have done it but next? if YOU Want to Get Others Please Visit Here ScishowEngineer   Then Follow US HERE and Join Telegram.

If You Want To Learn Something New Then Visit Our Official Channel YOUTUBE

## One thought on “Army Training CodeChef Solution”

1. I discovered your blog site on google and check a few of your early posts. Continue to keep up the very good operate. I just additional up your RSS feed to my MSN News Reader. Seeking forward to reading more from you later on!…