Army Training 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 points:¬†AiAi¬†where¬†(0<Ai<1000)(0<Ai<1000);
  • Defense points:¬†(1000‚ąíAi)(1000‚ąíAi);
  • Soldier type:¬†ATTACK¬†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.


  • 1‚ȧT‚ȧ1001‚ȧT‚ȧ100
  • 2‚ȧN‚ȧ10002‚ȧN‚ȧ1000
  • 0<Ai<10000<Ai<1000
  • Sum of¬†NN¬†over all test cases does not exceed¬†20002000.

Sample Input 1 

500 500
500 500 500
100 800 300 500
300 700 800 200

Sample Output 1 



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¬†=500‚čÖ500=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¬†=(1000‚ąí500)=500=(1000‚ąí500)=500

So,¬†rating¬†=1000‚čÖ500=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¬†=(1000‚ąí100)+(1000‚ąí300)=1600=(1000‚ąí100)+(1000‚ąí300)=1600

So,¬†rating¬†=1300‚čÖ1600=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¬†=(1000‚ąí300)+(1000‚ąí200)=1500=(1000‚ąí300)+(1000‚ąí200)=1500

So,¬†rating¬†=1500‚čÖ1500=2250000=1500‚čÖ1500=2250000. This is the maximum possible¬†rating¬†that we can achieve for the given army.

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

Related Posts

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!…

Leave a Reply

Your email address will not be published.