Write a code in C. You have n packets that you want to distribute among your alien
Fantastic news! We've Found the answer you've been seeking!
Question:
Write a code in C.
Transcribed Image Text:
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. 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.
Expert Answer:
Answer rating: 100% (QA)
CODE STARTS include long long int solveint n long long int An long long int Bn long long int maxlong ... View the full answer
Related Book For
Organizational behavior
ISBN: 9780077379438
5th edition
Authors: Steven L. McShane, Mary Ann Von Glinow
Posted Date:
Students also viewed these algorithms questions
-
Write a code in C for: A positive (strictly greater than zero) integer is called nice if it is of the form d00.0. In other words, a positive integer is nice if all its digits except the leftmost...
-
Write a code in C. The following iterative sequence is defined for the set of positive integers: n n/2 (n is even) n 3n + 1 (n is odd) Using the rule above and starting with 13, we generate the...
-
Write a code in C. Let d( n ) be defined as the sum of proper divisors of n (numbers less than n which divide evenly into n ). If d( a ) = b and d( b ) = a , where a b , then a and b are an amicable...
-
How do patterns of mental illness differ according to population? Name examples of where one psychological symptom could be interpreted in two different ways based on age/gender/identified problem.
-
a. Kline showed how not to move from one job to another. What did he do wrong? b. What should he have done? c. Kline knew that Fink and Ulrich were good at their jobs. Why couldn't he hire them to...
-
The Grignard route for the synthesis of (CH3)3CCO2H from (CH3)3CBr (Example 10.5) is far superior to the nitrile route. Explain why.
-
Find the condition indices and the variance decomposition proportions for the Hald cement data (Table B.21), assuming centered regressors. What can you say about multicollinearity in these data?...
-
George Company purchased land for use as its corporate headquarters. A small factory that was on the land when it was purchased was torn down, and before the new buildings foundation could be...
-
1.Assume that the equilibrium wage rate is 50AED in the labour market. 2.Discuss what happens if the government introduces a minimum wage of 30AED. 3.Discuss what happens if the government introduces...
-
At January 1, 2024, M. E. Gainor Corporation had outstanding the following securities: The following additional information is available: On September 1, 2024, M. E. Gainor sold 72 million...
-
A ball is thrown directly downward with an initial velocity of 9m/s from a height of 2 5 m. What is the time ( in s ) it takes to strike the ground.
-
During a review of indirect rates, the contracting officer finds that overhead costs were improperly reported and certified. Some of the overhead pools accounted for costs that should have not been...
-
If multiple parties have an interest in the same collateral, how does a court decide who get the collateral if theres a default?
-
What trends (in adaptations), in the phylogeny of land plants, occurred over evolutionary time? Explain
-
Imagine you are a top investor interested in buying the shares of a company and you would like to carry out an exhaustive due diligence on the company. Please explain the concept of due diligence,...
-
What is due diligence and why is it important? Name three typical types of due diligence. Who does it and why? What is influenced by its results?
-
Using the date below, contruct an income statement. Last year, Sun Skateboards had $ 2 0 0 , 0 0 0 in revenues. The company had $ 7 0 , 0 0 0 in COGS and $ 3 0 , 0 0 0 was SG&A . It was in the 2 1 %...
-
CdF2 (s) Cd+ (aq) + 2 F- (aq) 1. A saturated solution of CdF2 is prepared. The equilibrium in the solution is represented above. In the solution [Cd+] eq = 0.0585 M and [F-] eq = 0.117 M. a....
-
Two characteristics of creative people are that they have relevant experience and are persistent in their quest. Does this mean that people with the most experience and the highest need for...
-
You have just been hired as a brand manager of toothpaste for a large consumer products company. Your job mainly involves encouraging the advertising and production groups to promote and manufacture...
-
1. Identify the main conditions at Ford described in this case study that seem to have generated dysfunctional conflict. 2. What has Mulally done to reduce or remove these sources of conflict? In...
-
What is the present value of the following future amounts? a. $805 to be received 10 years from now discounted back to the present at 10 percent b. $376 to be received 5 years from now discounted...
-
To what amount will the following investments accumulate? a. $6,000 invested for 12 years at 12 percent compounded annually b. $7,500 invested for 8 years at 8 percent compounded annually c. $6,400...
-
At what annual rate would the following have to be invested? a. \($820\) to grow to \($1,988.12\) in 13 years b. \($320\) to grow to \($423.10\) in 6 years c. \($57\) to grow to \($290.30\) in 18...
Study smarter with the SolutionInn App