We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
this is my code, but it did not success in all cases
publicstaticintpoliceOperation(inth,List<int>criminals){returnOldMethod(h,criminals);}privatestaticintOldMethod(inth,List<int>criminals){intcreminalNumber=criminals.Count;intofficersNumber=0;inttmpFuelPayment=0;intfuelPayment=0;intpreviousLocation=0;intcurrentLocation=0;for(inti=0;i<creminalNumber;i++){//First Locationif(i==0){previousLocation=criminals[i];officersNumber++;continue;}//check which is more suitable, one more officer or pay for fuelcurrentLocation=criminals[i];tmpFuelPayment=fuelNeededToMove(previousLocation,currentLocation);if(tmpFuelPayment<h){// if it is last criminalif(i==creminalNumber-1){fuelPayment+=tmpFuelPayment;}}else{tmpFuelPayment=fuelNeededToMove(previousLocation,criminals[i-1]);fuelPayment+=tmpFuelPayment;tmpFuelPayment=0;previousLocation=criminals[i];officersNumber++;}}intsalaries=officersNumber*h;returnsalaries+fuelPayment;}privatestaticintfuelNeededToMove(intstartPos,intendPos){returnConvert.ToInt32(Math.Pow(endPos-startPos,2));}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Police Operation
You are viewing a single comment's thread. Return to all comments →
this is my code, but it did not success in all cases