Question: Write a code in C. You have n packets that you want to distribute among your alien friends. Unfortunately, if two aliens get different packets,

Write a code in C.

You have n packets that you want to distribute among your alien

friends. Unfortunately, if two aliens get different packets, they will get violent,

because each of them will certainly feel that the other packet was

better. Therefore, for your own safety, you need to ensure that all

You have n packets that you want to distribute among your alien friends. Unfortunately, if two aliens get different packets, they will get violent, because each of them will certainly feel that the other packet was better. Therefore, for your own safety, you need to ensure that all packets be exactly the same. The i-th packet consists of ai pebbles and bi swords. During one move, you can choose some packet 1sisn and do one of the following operations: take exactly one pebble from this packet (decrease ai by one); take exactly one sword from this packet (decrease bi by one): take exactly one pebble and exactly one sword from this packet (decrease both ai and bi by one). Of course, you can not take a pebble or sword if it's not present in the packet (so neither ai nor bi can become less than zero). As said above, all packets should be equal. This means that after some sequence of moves the following two conditions should be satisfied: al=a2==an and bl=b2=..=bn (and ai equals bi is not necessary). Your task is to find the minimum number of moves required to equalize all the given packets. You have to answer t independent test cases.

Step by Step Solution

3.40 Rating (169 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

CODE STARTS include long long int solveint n long long int An long long int Bn long long int maxlong ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Algorithms Questions!