Debug the Code class Solution { public: int shipwithinDays (vectorcint>& weights, int days) { int ma e;
Fantastic news! We've Found the answer you've been seeking!
Question:
Debug the Code
Transcribed Image Text:
class Solution { public: int shipwithinDays (vectorcint>& weights, int days) { int ma e; int right=e; for(auto x: weights) ma=max (ma, x); right+x; int left-ma; while(left<right) int mid=left+(left-right)/2; int curse, need=1; for (auto x:weights) if((cur+x)>mid) need++; curse; curt=x; if(need>days) left-mid+1; else right=mid; return left; Debug this code. It is not working on base testcase A conveyor belt has packages that must be shipped from one port to another within days days. The ith package on the conveyor belt has a weight of weights[il. Each day, we load the ship with packages on the conveyor belt (in the order given by weights ). We may not load more weight than the maximum weight capacity of the ship. Return the least weight capacity of the ship that will result in all the packages on the conveyor belt being shipped within days days. Example 1: Inputt weights - (1,2,3,4,5,5,7,8,9,10), days - 5 Output as Explanation A ship capacity of 15 is the ninimun to ship all the packages in s days 1ike this: 1st day: 1, 2, 3, 4,S 2nd dayI 6, 7 3rd daya 4th day:9 Sth day: 10 Note that the cargo ust be shipped in the order given, so class Solution { public: int shipwithinDays (vectorcint>& weights, int days) { int ma e; int right=e; for(auto x: weights) ma=max (ma, x); right+x; int left-ma; while(left<right) int mid=left+(left-right)/2; int curse, need=1; for (auto x:weights) if((cur+x)>mid) need++; curse; curt=x; if(need>days) left-mid+1; else right=mid; return left; Debug this code. It is not working on base testcase A conveyor belt has packages that must be shipped from one port to another within days days. The ith package on the conveyor belt has a weight of weights[il. Each day, we load the ship with packages on the conveyor belt (in the order given by weights ). We may not load more weight than the maximum weight capacity of the ship. Return the least weight capacity of the ship that will result in all the packages on the conveyor belt being shipped within days days. Example 1: Inputt weights - (1,2,3,4,5,5,7,8,9,10), days - 5 Output as Explanation A ship capacity of 15 is the ninimun to ship all the packages in s days 1ike this: 1st day: 1, 2, 3, 4,S 2nd dayI 6, 7 3rd daya 4th day:9 Sth day: 10 Note that the cargo ust be shipped in the order given, so
Expert Answer:
Answer rating: 100% (QA)
Mistake Line number 15 is wrong mid should calculate as midleftrightleft2 because right ... View the full answer
Posted Date:
Students also viewed these algorithms questions
-
Explain how to debug code by commenting it out.
-
My code is not working, can you check and edit the to do regions? EmployeeTester.java /**A class to demothe employee classes.*/ public class EmployeeTester { public static void main(String[] args) {...
-
I need an HTML Code for my website page When somebody searches Google and ask "what is my IP" My website page shows up in google search results and when person clicks the link to find his/her IP, it...
-
LOCATE APPROPRIATE CPT CODES ICD-10-CM (CPT) FOR PROCEDURES BELOW- Outpatient procedures only 1. INCISION AND DRAINAGE OF A CYST --- 2. DEBRIDEMENT - 3. SIMPLE REPAIR OF A SUPERFICIAL WOUND- 4....
-
What is the historical relationship between real GDP and inflation? What lesson might be learned from observing this relationship?
-
Descriptions of transactions and how they were recorded follows for October, 2012 for Ashley Acoustics, Inc. a. Received $3,600 cash from customer for three months of service beginning October 1,...
-
Sarah serves as Chief Executive Officer (CEO) for Biostate Corporation. Biostate is a pharmaceutical company that conducts research on the development of new cancer drugs. It has developed several...
-
Josh, John, and Hassan are partners in a retail lighting store. They share income and losses in the ratio of 2:2:1, respectively. The partners have agreed to liquidate the partnership. The...
-
6. For the given first order reaction 7. AB The half life of the reaction is 0.3010 min. The ration of the initial concentration of reactant to the concentration of reactant at time 2.0 min will be...
-
Steam enters a turbine at 9 MPa, 600C, and 60 m/s and leaves at 20 kPa and 90 m/s with a moisture content of 5 percent. The turbine is not adequately insulated, and it estimated that heat is lost...
-
A Junior Manager has been identified and placed on an accelerated leadership development programme but has not been able to keep up with the deliverables on the outcomes of the programme. As the...
-
How do corporate taxes affect the ModiglianiMiller theory of capital structure? Illustrate your answer with a practical example.
-
Gemini plc, an all-equity firm, is considering a 2.4 million investment that will be depreciated according to 25 per cent reducing balances. At the end of its 4-year life, the investment will be sold...
-
Assume a firms debt is risk-free, so that the cost of debt equals the risk-free rate, R f . Define A as the firms asset beta that is, the systematic risk of the firms assets. Define S to be the...
-
The returns of Lockhart Group plc and TJC plc are given below. Using the following returns, calculate the average returns, the variances, and the standard deviations for Lockhart Group and TJC: Year...
-
After graduating from university you get a job for a non-dividend paying company which has recently listed on the stock exchange. Your manager tells you that the company does not favour the NPV...
-
Identify the vowel sound symbol of the underlined letter/s: (do not forget your brackets for your answers) 1. f a rm 11 b ea k 2. e lf 12. d aw n 3. l e i 13. c u p 4. l ea gue 14. f ir st 5. d ea th...
-
Representative data read from a plot that appeared in the paper Effect of Cattle Treading on Erosion from Hill Pasture: Modeling Concepts and Analysis of Rainfall Simulator Data (Australian Journal...
-
The position of a particle undergoing simple harmonic motion is given by \(x(t)=20 \cos (8 \pi t)\), where \(x\) is in millimeters and \(t\) is in seconds. For this motion, what are the (a)...
-
Fill in the blanks to make the following statements correct. a. It is difficult to compare two or more data series when absolute numbers and different units are used. For that reason we construct...
-
Fill in the blanks to make the following statements correct. a. The term quantity demanded refers to ___________ purchases by consumers, whereas quantity exchanged refers to ___________ purchases by...
Study smarter with the SolutionInn App