Drill

ProblemsC# › logistics

Parcel discount band

mediumlogisticsArraysPrefix sumsMathC#

A monthly contract discounts each parcel once the month's total reaches a threshold: every parcel from then on ships 15% cheaper.

BulkDiscountBand(parcelCosts: list<int>, threshold: 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 BulkDiscountBand(List<int> parcelCosts, int threshold) {
    
}

Worked examples

CallResult
BulkDiscountBand(new List<int> { 100, 100, 100, 100 }, 250)370
BulkDiscountBand(new List<int> { 100, 100 }, 200)185
BulkDiscountBand(new List<int> { 100, 100, 100 }, 1000)300
BulkDiscountBand(new List<int> { }, 0)0

Hint

Walk the values; once the running total crosses the threshold everything from that parcel on is discounted.

Reference solution in C#
public int BulkDiscountBand(List<int> parcelCosts, int threshold) {
    int total = 0, running = 0;
    foreach (int cost in parcelCosts) {
        running += cost;
        total += (running >= threshold) ? (cost * 85) / 100 : cost;
    }
    return total;
}

The same problem in another language

More logistics problems in C#