Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
Step: 1
CODE STARTS include long long int solveint n long long int An long long int Bn long long int maxlong ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started