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

public 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#
public int ParcelCost(int weight) {
    if (weight < 0) return 0;
    return 300 + Math.Max(0, weight - 5) * 60;
}

The same problem in another language

More logistics problems in C#