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....
-
Heat Loss During Breathing. In very cold weather a significant mechanism for heat loss by the human body is energy expended in warming the air taken into the lungs with each breath. (a) On a cold...
-
A 0.2-cm-thick, 10-cm-high, and 15-cm-long circuit board houses electronic components on one side that dissipate a total of 15 W of heat uniformly. The board is impregnated with conducting metal...
-
4. How will the consolidated assets and consolidated net income for 2016 be affected by the intercompany sale? a Consolidated net assets will decrease, and consolidated net income will increase. b...
-
Compute the initial price of a swaption that matures at time t =5 and has a strike of 0. The underlying swap is the same swap as described in the previous question with a notional of 1 million. To be...
-
please make sure to give the correct answer PSa 4-2 Calculate Social Security Tax For each of the following employees, calculate the Social Security tax for the weekly pay period described: NOTE: For...
-
Go to the Webinars worksheet. DeShawn wants to determine the number of webinars the company can hold on Tuesdays and Thursdays to make the highest weekly profit without interfering with...
-
assume the average unit sales price is $2.00 and the average unit cost is $1.10 for beverages. what is the effect of selling merchandise along with beverages on breakeven? fix cost is $90,000
-
Which one of the following therapists' approaches has been integrated into several other therapies in the West? 1. Naikan therapy 2. Morita therapy 3. mindfulness meditation
-
What does this scatter plot tell us? Check ALL below that are true from the Scatter Plot. Y is cumulative total barrels and x is number of active wells. 1. If there were 550 active wells, we would...
-
Millie runs a small company that makes customised notebooks with personalised details on the cover and inserts. You promote your product as a great gift idea, and your holiday orders break your...
-
Excel ACC 311 Project Two Workbook Template - View-only Search (Alt + Q) File Home Insert Draw Page Layout Formulas Data Review View Help 12 B A ... ab Ev F10 1 2 3 4 5 6 fx A B Posey's Pet Emporium...
-
Imagine that you are the change manager for acompany that does business entirely via the Internet. The head development engineercalls to indicate he wants to make a small change to one of the...
-
1. Prepare a cost of production report for the Mixing Department 2. Determine the cost of goods sold indicate the number of units and unit costs). 3. Determine the finished goods inventory, May 31,...
-
Havel says the grocer doesnt believe what is on the sign and indeed, he says the grocers customers will barely notice it. But Havel maintains that the sign serves a specific function. How would you...
-
Often, various health conditions are related. That is, if one has one condition, one is likely to have another condition. Using the PewHealth index, run a correlation matrix using the five recoded...
-
Several of the ANES feeling thermometers concern religion. Run three simple regression equations, all of them using the Christian Fundamentalist feeling thermometer as your independent variable. For...
-
Do kids engage in a higher frequency of bad cyberbehavior as they get older? Use the Childs Bad Cyberbehavior Index in the PewKids dataset as your dependent variable, and use childs age as your...
![Mobile App Logo](https://dsd5zvtm8ll6.cloudfront.net/includes/images/mobile/finalLogo.png)
Study smarter with the SolutionInn App