Answered step by step
Verified Expert Solution
Link Copied!

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 ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Organizational Behavior Emerging Knowledge And Practice For The Real World

Authors: Steven McShane, Mary Von Glinow

5th Edition

978-0077379438, 0077379438

More Books

Students also viewed these Algorithms questions

Question

What are prepaid expenses? Give four examples.

Answered: 1 week ago

Question

2. What is e-HRM? Explain about different EHRM technologies

Answered: 1 week ago