Drill

ProblemsC++ › logistics

What does this parcel cost to send

easylogisticsMathC++

A courier prices every parcel as: the first five kilograms cost 300 (minor units) and each further kilogram adds 60.

parcelCost(weight: int) → int

C++ needs a compiler and Drill does not host one yet, so this page is the reference rather than an exercise: the problem, worked examples, and the solution in full. To type it out, the same problem runs in Python.

Solve it in Python →

Where you start

int parcelCost(int weight) {
    
}

Worked examples

CallResult
parcelCost(3)300
parcelCost(5)300
parcelCost(6)360
parcelCost(10)600

Hint

Subtract the free five, multiply what is left, and add the base.

Reference solution in C++
int parcelCost(int weight) {
    if (weight < 0) return 0;
    return 300 + std::max(0, weight - 5) * 60;
}

The same problem in another language

More logistics problems in C++