GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Wednesday, 6 July 2022

[Solution] Army Training CodeChef Solution | Solution Codechef


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

The army consists of N soldiers where each soldier has 3 parameters:

  • Attack pointsAi where (0<Ai<1000);
  • Defense points(1000Ai);
  • 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.

Solution Click Below:-  👉CLICK HERE👈
👇👇👇👇👇


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 32-bit integer.
Remember to use 64-bit data types, such as long long in C++.

Input Format

  • The first line of input will contain a single integer T, 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 N — the number of soldiers in the army.
    • The next line contains the array A — where Ai denotes the attack points of the ith soldier.

Output Format

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

Constraints

  • 1T100
  • 2N1000
  • 0<Ai<1000
  • Sum of N over all test cases does not exceed 2000

No comments:

Post a Comment